Saturday, October 5, 2013

Find which CheckBox is Checked inside GridView C#

Below is a simple code that will help you finding all the CheckBox inside Grid View weather they are checked or Not Checked.

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

We Define a variable called gvRow of type GridViewRow this will be use to hold information about each row

Now Because it is Control and it's type is CheckBox so we will need to typecast the result in CheckBox

I hope it was informative for you, and I would like to Thank You for reading

No comments:

Post a Comment