Home All Groups Group Topic Archive Search About

Checkboxes in a datagrid

Author
4 Jan 2007 1:26 PM
arun@greettech.com
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?

Author
4 Jan 2007 2:08 PM
arun@greettech.com
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

AddThis Social Bookmark Button