mercredi 1 avril 2015

Checkchanged not firing when inside a gridview in asp.net

I have a gridview and inside it is a checkbox for the status of the items, the checkbox has checkchanged event but when I'm trying to check or uncheck it, the checkchanged is not firing.


here is the code for the gridview with 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' where item_id = @item_id ",con);
cmd.Parameters.AddWithValue("@item_id", cmd);
cmd.ExecuteNonQuery();

con.Close();
}


Thanks in Advance!





Aucun commentaire:

Enregistrer un commentaire