GridView Checkbox

netpicker9
01-17-2007, 08:22 PM
Hi,

I have Three questions

I have checkbox in GridView with AutoPostBack="True"

Question 1.
Once I click the checkbox, page is refreshing and checkbox is showing as unchecked..
How to show/keep the checkbox in checked state??

Code:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" />
<asp:BoundField DataField="CategoryName" HeaderText="CategoryName" />
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Question 2.

If I place a Breakpoint here, Control is not coming here..

Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim checkbox As CheckBox = CType(sender, CheckBox)
Dim row As GridViewRow = CType(checkbox.NamingContainer, GridViewRow)
End Sub

Question 3:

Is there anyway, I can refresh the GridView only without refreshing whole page.. (without Ajax, because I am using asp.net 2.0)

Thanks in advance.

wayneph
01-18-2007, 08:20 AM
I think 1 and 2 boil down to the same problem. It seems like you are rebinding the gridview in page_load. That would reset the checkbox and "eat" the event.

Ajax is the only way to do a partial refresh. (Although, not necessiarially the Ajax.Net Framework.) It's just using JavaScript to get information. If I'm not mistaken, the GridView has some built in features that use the ICallBack interface, to sort and such without a full PostBack. I'm sure if you investigate into that, you could come up with a way to do it. (I'd personally look into using the Ajax.Net Framework.)

netpicker9
01-18-2007, 03:28 PM
Many thanks for the solution..

Now, I have 5 ckeckboxes in a Grid.. (C1, C2,..., C5)

First I selected C1 and page is refreshed..

Next I selected C3 and page is refreshed,

I doubt is when C3 is checked, how to check C1 state, whether its checked or not..

I am building an array based on selected checkboxs..

wayneph
01-18-2007, 05:26 PM
you have two options...
1. Loop through the items in the Grid and Check manually each time.
2. Create a variable in the ViewState or Session that mirrors the items selected in the Grid.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum