Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > ASP.Net > GridView Checkbox


Reply
 
Thread Tools Display Modes
  #1  
Old 01-17-2007, 08:22 PM
netpicker9 netpicker9 is offline
Centurion
 
Join Date: Jun 2005
Posts: 127
Default 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.
Reply With Quote
  #2  
Old 01-18-2007, 08:20 AM
wayneph's Avatar
wayneph wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

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
Reply With Quote
  #3  
Old 01-18-2007, 03:28 PM
netpicker9 netpicker9 is offline
Centurion
 
Join Date: Jun 2005
Posts: 127
Default 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..
Reply With Quote
  #4  
Old 01-18-2007, 05:26 PM
wayneph's Avatar
wayneph wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->