Can you please help me on this, I get the check box control value as false always even when I check the control in gridview.
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox CheckBox1 = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (CheckBox1 != null)
{
if (CheckBox1.Checked)
{
query = GridView1.Rows[i].FindControl("Label1") + ",";
}
}
}
Are you databinding on Page_Load method? If yes, you must do this:
If you don’t do this, your
DataGridViewwill be databound even if it is aPostBack. This way no matter what you checked, theDataGridViewwill be repopulated from the data source for your postbacks.Using the above code, when you do
if(!IsPostBack), it will retain the checkbox’s viewstate value and you get the correctCheckedstatus.