I have a checkboxes inside a gridview which are checked and unchecked based on database value (1 and 0)
I am trying to update those checkboxes by checking and unchecking them before clicking save button, and then update the database table but the problem is it doesn't update the value of checkbox in the database,
here is what I tried:
<asp:GridView ID="GridView1" CssClass="datatable" runat="server" AutoGenerateColumns="False" AllowPaging="True" PageSize="10"
AllowSorting="True" EnableViewState="false" width="863px" DataSourceID="SqlDataSource1" >
<Columns >
<asp:TemplateField HeaderText="emai" SortExpression="req_subject" >
<ItemTemplate>
<asp:CheckBox ID="CheckBox_h_email" runat="server" Checked='<%# Convert.ToInt32(Eval("prev_1")) == 1 ? true : false %>' />
</ItemTemplate>
<ItemStyle Width="90px" />
<HeaderStyle Width="90px" />
<FooterStyle Width="90px" />
</asp:TemplateField
</asp:GridView>
protected void btn_save(object sender, EventArgs e)
{
using (SqlConnection sqlCon = new SqlConnection(@""))
{
sqlCon.Open();
CheckBox txt = GridView1.Rows[3].FindControl("CheckBox_h_email") as CheckBox;
if (txt.Checked)
{
SqlCommand cmd = new SqlCommand("update [admins_table] set [prev_1] = '0'", con);
}
else if (!txt.Checked)
{
SqlCommand cmd = new SqlCommand("update [admins_table] set [prev_1] = '0'", con);
}
}
con.Close();
}
Aucun commentaire:
Enregistrer un commentaire