开发者

Postback problem with checkbox (within gridview) on button click event

开发者 https://www.devze.com 2023-01-29 11:13 出处:网络
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 d

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
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消