PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET Checkboxes in a datagrid

Reply

Checkboxes in a datagrid

 
Thread Tools Rate Thread
Old 04-01-2007, 01:26 PM   #1
arun@greettech.com
Guest
 
Posts: n/a
Default Checkboxes in a datagrid


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?

  Reply With Quote
Old 04-01-2007, 02:08 PM   #2
arun@greettech.com
Guest
 
Posts: n/a
Default Re: Checkboxes in a datagrid

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

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off