Saturday, October 12, 2013

Get GridView Column Value of Control C#

In order to find value of certain column of gridview, we need to find weather they are control or simple text

If they are control like Label, Hyperlink etc than we must use the findControl method to get the value

The following code will show you how to get value of a HyperLink type Column



   1:  foreach (GridViewRow gvRow in gv1.Rows)
   2:              {
   3:                  CheckBox chkItem = (CheckBox)gvRow.Cells[0].FindControl("GvCheckBox");
   4:                  if (chkItem.Checked)
   5:                  {
   6:                        HyperLink abc = (HyperLink)gv1.Rows[1].Cells[2].FindControl("hlFileName");
   7:                  }
   8:   
   9:                  else
  10:                  {
  11:                      //this code will execute if the CheckBox is Not Checked
  12:                  }
  13:              }
asdasdasd

Inside the (chkItem.Checked)

We first declare a variable abc of type HyperLink

Than using (HyperLink) we type cast the result which we will get

The Name of my GridView is gv1

To Change Rows just change the index or we can use variable as well

the FindControl() method which accepts 1 parameter we provide the Column Header and thus we are able to get the value of that column

I hope it was informative for you, And I would like to Thank you for reading.

No comments:

Post a Comment