A checkbox is added to the template column of the DataGrid, and if paging is set on the DataGrid, the checkbox's state changes to its original state when the checkbox on the previous page is returned to the primary page. <?xml:namespace prefix = o ns = "Urn:schemas-microsoft-com:office:office"/>
If you want to save the status of the checkbox, you can save it with the session, which I implemented:
1. First, set up the DataGrid.
<asp:datagrid id= "DataGrid1" style= "Z-INDEX:101; left:12px; Position:absolute; top:88px "runat=" Server "allowpaging=" True "width=" 416px "height=" 248px ">
<alternatingitemstyle backcolor= "#EEEEEE" ></AlternatingItemStyle>
<itemstyle font-size= "12px" font-names= "Song Body" ></ItemStyle>
<footerstyle horizontalalign= "Center" ></FooterStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:checkbox id= "CheckBox1" runat= "Server" ></asp:checkbox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
2. In the Global.asax file, the Session is established in the Session_Start event
Sub session_start (ByVal sender as Object, ByVal e as EventArgs)
' Fires when the session starts
Dim checks As Boolean () = New Boolean (10000) {}
Dim I as Integer
For i = 0 to 10000
Checks (i) = False
Next
Session.add ("Checkboxchecks", checks)
End Sub
3. In the PageIndexChanged event of the DataGrid:
Private Sub datagrid1_pageindexchanged (ByVal source as Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles datagrid1.pageindexchanged
Dim count as Integer
Dim CNN as Oledb.oledbconnection = New oledb.oledbconnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/ Userlog.mdb ")
Dim da as New oledb.oledbdataadapter ("select * from mm", CNN)
Da. Fill (DST)
Count = DST. Tables (0). Rows.Count ' Total number of records in the DataGrid;
Dim Check as Boolean ()
Check = Me.session ("checkboxchecks") ' Check () is an array of record checkbox states, saved with the Session.
Dim J as Integer
For j = 0 to Datagrid1.pagesize-1
Dim Che as CheckBox = Datagrid1.items (j). Cells (0). FindControl ("CheckBox1")
If not Che was nothing Then
If che.checked = True Then
Check (Datagrid1.currentpageindex * datagrid1.pagesize + j) = True
Else
Check (Datagrid1.currentpageindex * datagrid1.pagesize + j) = False
End If
End If
Next
Datagrid1.currentpageindex = E.newpageindex
Dim DS as New DataSet ()
Da. Fill (ds, "a")
DataGrid1.DataSource = ds
Datagrid1.databind ()
Dim I as Integer
For i = 0 to Datagrid1.pagesize-1
Dim Cx2 as CheckBox = Datagrid1.items (i). Cells (0). FindControl ("CheckBox1")
IF Check (Datagrid1.currentpageindex * datagrid1.pagesize + i) = True Then
cx2.checked = True
Else
cx2.checked = False
End If
Next
End Sub
in this way, you can use the session to implement the State saving problem after the CheckBox page.