I am trying to store the checboxes values between paginations so if i go from 1 page to another and ocme back the the checkbox checked would persist.
Protected Sub gv_InforWO_PageIndexChanging(sender As Object, e As GridViewPageEventArgs)
Try
gv_InforWO.PageIndex = e.NewPageIndex
If chkFiltersAvailable.Checked = False Then
chkSelectAll.Checked = False
BindGridInfoWO()
'btnSync_Click(Nothing, Nothing)
Else
BindGridInfoWO()
' btnSync_Click(Nothing, Nothing)
End If
'checkbox persistence code
Dim d As Integer = gv_InforWO.PageCount
Dim values() As Boolean = New Boolean((gv_InforWO.PageSize) - 1) {}
Dim chb As CheckBox
Dim count As Integer = 0
Dim i As Integer = 0
Do While (i < gv_InforWO.Rows.Count)
chb = CType(gv_InforWO.Rows(i).FindControl("chkSelect"), CheckBox)
If (Not (chb) Is Nothing) Then
values(i) = chb.Checked
End If
i = (i + 1)
Loop
Session(("page" + CType(gv_InforWO.PageIndex, String))) = values
Catch ex As Exception
lblWaitingMsg.Text= ex.Message
End Try
End Sub
On pre-render
Protected Sub gv_InforWO_PreRender(sender As Object, e As EventArgs)
Try
If (Not (Session(("page" + CType(gv_InforWO.PageIndex, String)))) Is Nothing) Then
Dim chb As CheckBox
Dim values() As Boolean = CType(Session(("page" + CType(gv_InforWO.PageIndex, String))), Boolean())
Dim i As Integer = 0
Do While (i < gv_InforWO.Rows.Count)
chb = CType(gv_InforWO.Rows(i).FindControl("chkSelect"), CheckBox)
chb.Checked = values(i)
i = (i + 1)
Loop
End If
Catch ex As Exception
End Try
End Sub
but it doesn't persist the value and comes as false even if I tick the boxes.
Aucun commentaire:
Enregistrer un commentaire