I have a column of checkboxes to select the records in the gridview but i am struggling to determine which checkboxes were checked on postback caused by button click.I used the following code but it doesnt work.
protected void btnSave_Click(object sender, EventArgs e)
{
foreach (GridV开发者_如何学JAVAiewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("Chkgridselect");
if (cb.Checked)
{
int id = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
}
}
}
Can anyone please rectify the above coding?
This is what i do and it is working:
foreach (GridViewRow row in GridView1.Rows)
{
// Access the CheckBox
CheckBox cb = (CheckBox)row.FindControl("Chkgridselect");
if (cb != null && cb.Checked)
{
//dostuff
}
}
精彩评论