asp.net gridview checkbox selection

前端 未结 2 1723
[愿得一人]
[愿得一人] 2020-12-29 14:37

Need some help to solve this.

I have a gridview and inside the gridview I have a checkbox and after clicking the checkbox, I am doing a postback event and trying to

2条回答
  •  误落风尘
    2020-12-29 14:52

    Try this:

    CheckBox chkBx = sender as CheckBox;
    

    Rather than iterate all the rows.

    I haven't used CheckBox's in a GridView in this way myself. Usually I would use the GridView's OnRowCommand event instead and use the RowIndex or CommandArgument value to update the database.

    Thinking about it OnRowcommand could be tricky for a CheckBox to fire, a better solution might be sticking with the CheckChanged event of the checkbox and navigate up to the GridViewRow serverside using controls NamingContainer. Something like:

    GridViewRow row = chkBx.NamingContainer as GridViewRow;
    

    I'm assuming the goes CheckBox => Cell => Row if you Google ASP.NET NamingContainer you'll get some more specifics.

提交回复
热议问题