473,761 Members | 9,864 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Paging DataGrid Checkbox Persistence

Have a paging datagrid with a checkbox control in column(0).
ViewState is enabled.
I check the checkbox in first row of the grid on a page and then
the program hits this event:

Private Sub dgRegGrid_PageI ndexChanged(ByV al source As Object, ByVal e
As System.Web.UI.W ebControls.Data GridPageChanged EventArgs) Handles
dgRegGrid.PageI ndexChanged

I then do a loop to check the checkbox state.

For i = 0 To dgRegGrid.Items .Count - 1
chk = CType(dgRegGrid .Items.Item(i). Cells(0).FindCo ntrol("chkAtten ded"),
CheckBox)
If chk.Checked = True Then
objCustomer.Upd ateCheckBoxStat e(dgRegGrid.Dat aKeys(i),
"Y")
Else
objCustomer.Upd ateCheckBoxStat e(dgRegGrid.Dat aKeys(i),
" ")
End If
Next

Oddly, the chk.Checked value comes up FALSE when the row is checked.
I have confirmed that the datakey matches the row being read in at the
time.

Any suggestions on how to get at these check values?

Ian
Nov 18 '05 #1
1 4160
Hi Ian,

Here is a sample that may help you. Note that the check boxes will be reset
to unchecked each time you change pages. The results output is from the
state of the check boxes when you selected to change the page.

**** ASPX
A DataGrid with AutoGenerateCol umns turned off and containing one template
column which contains a check box.

<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateCol umns="False">
<Columns>
<asp:TemplateCo lumn>
<ItemTemplate >
<asp:CheckBox id="CheckBox1" runat="server"> </asp:CheckBox>
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
</asp:DataGrid>
</form>

**** Code-behind
Imports System.Data.Sql Client

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.Allow Paging = True
DataGrid1.PageS ize = 10
DataGrid1.Pager Style.Mode = PagerMode.NextP rev
DataGrid1.Pager Style.NextPageT ext = "Next"
DataGrid1.Pager Style.PrevPageT ext = "Prev"
Bind()
End If
End Sub

Private Sub Bind()
Dim MyList As New ArrayList
Dim i As Int32
For i = 0 To 25
MyList.Add(i)
Next
DataGrid1.DataS ource = MyList
DataGrid1.DataB ind()
End Sub

Private Sub DataGrid1_PageI ndexChanged(ByV al source As Object, ByVal e
As System.Web.UI.W ebControls.Data GridPageChanged EventArgs) Handles
DataGrid1.PageI ndexChanged
Dim i As Int32
For i = 0 To DataGrid1.Items .Count - 1
Dim ck As CheckBox
ck = DataGrid1.Items (i).Cells(0).Fi ndControl("Chec kBox1")
Response.Write( ck.Checked & "<br>")
Next
DataGrid1.Curre ntPageIndex = e.NewPageIndex
Bind()
End Sub
Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
From: do***********@y ahoo.com (iforsyth)
Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
Subject: Paging DataGrid Checkbox Persistence
Date: 9 Jan 2004 11:50:20 -0800
Organization: http://groups.google.com
Lines: 30
Message-ID: <d8************ **************@ posting.google. com>
NNTP-Posting-Host: 63.167.0.3
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google. com 1073677821 22758 127.0.0.1 (9 Jan 2004 19:50:21 GMT) X-Complaints-To: gr**********@go ogle.com
NNTP-Posting-Date: Fri, 9 Jan 2004 19:50:21 +0000 (UTC)
Path: cpmsftngxa07.ph x.gbl!cpmsftngx a10.phx.gbl!TK2 MSFTNGXA05.phx. gbl!TK2MSFTNGP0 8
..phx.gbl!newsf eed00.sul.t-online.de!t-online.de!news-spur1.maxwell.s yr.edu!n
ews.maxwell.syr .edu!postnews1. google.com!not-for-mail Xref: cpmsftngxa07.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:2010 26
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet

Have a paging datagrid with a checkbox control in column(0).
ViewState is enabled.
I check the checkbox in first row of the grid on a page and then
the program hits this event:

Private Sub dgRegGrid_PageI ndexChanged(ByV al source As Object, ByVal e
As System.Web.UI.W ebControls.Data GridPageChanged EventArgs) Handles
dgRegGrid.PageI ndexChanged

I then do a loop to check the checkbox state.

For i = 0 To dgRegGrid.Items .Count - 1
chk = CType(dgRegGrid .Items.Item(i). Cells(0).FindCo ntrol("chkAtten ded"), CheckBox)
If chk.Checked = True Then
objCustomer.Upd ateCheckBoxStat e(dgRegGrid.Dat aKeys(i),
"Y")
Else
objCustomer.Upd ateCheckBoxStat e(dgRegGrid.Dat aKeys(i),
" ")
End If
Next

Oddly, the chk.Checked value comes up FALSE when the row is checked.
I have confirmed that the datakey matches the row being read in at the
time.

Any suggestions on how to get at these check values?

Ian


Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3860
by: Paul Hale | last post by:
Hi, Currently using VS2005 c# Scenario: I have a gridview control displaying many items with paging enabled. Column is a checkbox column which users can check, but when the gridview is paged to another page and then back again, the value of the checkbox has been forgotten. Is there a better way of persisting the values through the pages in VS2005 other than writing tedious code behind in the OnPageIndexChanging event? Maybe using the...
3
4884
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
2
2585
by: RJN | last post by:
Hi Sorry for posting again. I have a datagrid which is put inside a div tag to make it scrollable. I need to page the datagrid. The page numbers appear at the bottom of the datagrid and has to be scrolled down completely to see the page number links. The page number should always be visible outside the scroll bar. Basically I want to create the paging links dynamically and on click of this it should fire PageIndexChanged event.
2
1301
by: Luis Esteban Valencia | last post by:
I have a data grid control with a templated checkbox column residing in a asp.net user control. The checkbox boolean state determines if the item is later added or removed from another database table. The checkbox column is not part of the db schema, but is added at run time and initialized separately before binding the data table to the grid. A batch update is processed via a server side method invoked from a submit button outside the...
6
1815
by: Shawn | last post by:
Hi. I already have a datagrid where I'm using paging. I have a stored procedure that fills a temp table with 200-500 rows and then sends back 10 records at the time. When I go to page 2 the SP fills the temp table again and returns rows 10-19. The temp table is dropped after each call to the SP, so it has to be created and filled every time the user changes page in the datagrid. My question is this: Would it be more efficient to...
2
2223
by: asad | last post by:
Hello friends, i am designing a ASP.NET page where i want to use custom paging bcoz data is too heavy so pls tell me how can i use custom paging in ASP.NET Thanks
2
1394
by: Jignesh Desai | last post by:
Info:: Most of you must have worked on paging feature of DataGrid. its works fine as long as you have more no of records to show, but if you have configured 20 records per page and no of records you retrieved is less then 20 then also pager gets rendered at the bottom of the grid showing "1". most of us do not bother about it , but Clients ,,,uff... Solution: SQLDataAdapter.Fill(DS,"Emp") If DS.Tables("Emp").Rows.Count >...
0
4197
by: =?Utf-8?B?V0I=?= | last post by:
Hi, I have a .NET page which has a gridview of customers from Northwind database. There's a checkbox for each customer and the gridview allows paging. I would like to be able to persist the checkbox status while paging. I'm starting with the code below but I can't get it to work. You can check some of the checkboxes and when you click on the pager, no selection is reflected by the trace. Why's that?
2
1939
by: rn5a | last post by:
In a shopping cart app, a ASPX page retrieves the order details & personal details of a user from a MS-Access database table depending upon the username of the user. The order details of a particular order (like ProductID, Name, Description, Quantity etc.) are displayed in one DataGrid where as the personal details of the buyer corresponding to this order (like Name, E-Mail, Shipping & Billing Address etc.) are displayed in another...
0
9531
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7332
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5229
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5373
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3881
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.