 |
 |

01-17-2007, 08:22 PM
|
|
Centurion
|
|
Join Date: Jun 2005
Posts: 127
|
|
GridView Checkbox
|
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.
|
|

01-18-2007, 08:20 AM
|
 |
Web Junkie
Retired Moderator * Expert *
|
|
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
|
|
|
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.)
|
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
|

01-18-2007, 03:28 PM
|
|
Centurion
|
|
Join Date: Jun 2005
Posts: 127
|
|
Thanks
|
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..
|
|

01-18-2007, 05:26 PM
|
 |
Web Junkie
Retired Moderator * Expert *
|
|
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
|
|
|
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.
|
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|