Add Checkbox in the DataGrid template column. If you set a pagination for the DataGrid, the checkbox that is already selected on the previous page is returned to the original page, and the status of checkbox will become an initial state.
If you want to save the status of Checkbox, you can save it with sessions, I do this:
1. First, establish a DataGrid.
Itemtemplate>
asp: templateColumn>
Columns>
ask: DataGrid>
2, in the global.asax file, session_start events are established in the session_start event
Sub session_start (Byval E AS Object, BYVAL E As Eventargs) Starts Dim Checks as Boolean () = New Boolean (10000) = 0 to 10000 Checks (i) = FALSE NEXT Session.Add ("CheckboxChecks", Checks) End Sub
3. In the DataGrid's pageIndexchanged event:
Private sub DataGrid1_pageIndexchanged (Byval e as system.Web.ui.WebControls.DataGridPageChangeDeventargs) Handles DataGrid1.pageIndexchanged
DIM Count As Integer
DIM CNN AS OLEDB.OLDBCONNECTION = New OLEDB.OLEDBCONNECTION ("provider = microsoft.jet.Oledb.4.0; data source = c: /userlog.mdb") DIM DA AS New OLEDB.OLDBDATAADAPTER ("SELECT * FROM MM", CNN )
Da.fill (DST)
Count = dst.tables (0). Rows.count 'DataGrid number;
DIM Check as Boolean ()
Check = Me.Session ("CheckBoxChecks") 'Check () is an array that records the Checkbox status and saves it with 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 chess 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 kil
Cx2.checked = true
Else
Cx2.checked = false
END IF
NEXT
End Sub
This will use the session to implement the status saving problem after the checkbox turn page.