c# - Checkchanged not firing when inside a gridview in asp.net -
i have gridview , inside checkbox status of items, checkbox has checkchanged event when i'm trying check or uncheck it, checkchanged not firing.
here code gridview checkbox inside
<asp:gridview id="dgvitems" runat="server" onrowcreated="dgvitems_rowcreated" onrowdatabound="dgvitems_rowdatabound" onselectedindexchanged="dgvitems_selectedindexchanged" onrowdeleting="dgvitems_rowdeleting"> <columns> <asp:templatefield headertext ="status"> <itemtemplate> <asp:checkbox id="chkstatus" runat="server" checked = <%# (string)eval("item_status") == "active" ? true : false %> oncheckedchanged="chkstatus_checkedchanged" autopostback="true" /> </itemtemplate> </asp:templatefield> </columns> </asp:gridview> protected void chkstatus_checkedchanged(object sender, eventargs e) { gridviewrow row = dgvitems.selectedrow; string item_id = row.cells[0].text.tostring(); con.open(); sqlcommand cmd = new sqlcommand("update items set item_status = 'inactive' item_id = @item_id ",con); cmd.parameters.addwithvalue("@item_id", cmd); cmd.executenonquery(); con.close(); }
thanks in advance!
two things coming mind:
- your
page_load
not take care ofispostback
-property, databinding grid, on postback. prevents events. gridviewrow row = dgvitems.selectedrow;
null
.
use code gridviewrow
checked checkbox
:
checkbox chkstatus = (checkbox) sender; gridviewrow row = (gridviewrow) chkstatus.namingcontainer;
Comments
Post a Comment