开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜