Checkboxes in a datagrid

A

arun

I have a GridView with a a checkbox as below.

<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true"
checked='<%# Eval("BooleanField1") %>'
OnCheckedChanged="CheckBox1_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="true"
checked='<%# Eval("BooleanField2") %>'
OnCheckedChanged="CheckBox2_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>

I want the database to get updated whenever I check or uncheck the
CheckBox1,
ie the value of "BooleanField1" in the database should be changed to
True or False.
And same with CheckBox2.

How can I accomplish this?
 
A

arun

Now I can access the DataKeyNames by the following code

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox checkbox = (CheckBox)sender;
GridViewRow row = (GridViewRow)checkbox.NamingContainer;
Response.Write(row.Cells[0].Text);
}

But I have kept the 0th column visible=false. Then I cant get it by the
above code. Is there any solution for this
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top