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:

  1. your page_load not take care of ispostback-property, databinding grid, on postback. prevents events.
  2. gridviewrow row = dgvitems.selectedrow; null.

use code gridviewrow checked checkbox:

checkbox chkstatus = (checkbox) sender; gridviewrow row = (gridviewrow) chkstatus.namingcontainer; 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -