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