user2792158
user2792158

Reputation: 11

check boxes values saved in session across mutiple pages

I am working in as custom Webgrid built with infragistics. I am able to iterate thru the rows to get to the checkboxes and store the boxes that are check values into a session.

This is what is happen right now. On any page I click four checkboxes to change status to true. When I go to the next page and go back to previous page I have a method that repopulate the check boxes base on values and set those boxes to true. The method works

The problem is when on any page I click my boxes, go to the next page click on additional boxes, go back to the previous page the boxes are unchecked. Yet if I go to the next page my boxes are checked.

The desire help is to save the checkboxes checked values across multiple pages in to a session.

 Public Sub Check_Clicked(sender As Object, e As EventArgs)
    Dim data As New List(Of String)
    Dim loadnumbers As String = ""
    Const comma As Char = (",")
    Dim dp As String
    Try
        If Session("data") IsNot Nothing Then

            For Each row As UltraGridRow In iuwgLoadGrid.Rows
                Dim myCellItem = GetGridCell(row, row.Index, "SELECTLOAD")
                Dim myCheckBox = DirectCast(myCellItem.FindControl("chkSelectLoad"), CheckBox)
                If (myCheckBox.Checked = True) Then
                    loadnumbers = loadnumbers & CType(GetGridCell(row, "lgh_number").Value, Integer)
                    Dim val As String = Session("data")
                    Dim arrVal As String() = val.Split(",")
                    For Each s As String In arrVal
                        If Not data.Contains(s) Then
                            data.Add(s)
                        End If
                        Session("data") = data
                    Next
                End If
            Next
        Else
            For Each row As UltraGridRow In iuwgLoadGrid.Rows
                Dim myCellItem = GetGridCell(row, row.Index, "SELECTLOAD")
                Dim myCheckBox = DirectCast(myCellItem.FindControl("chkSelectLoad"), CheckBox)
                If (myCheckBox.Checked = True) Then
                    loadnumbers = loadnumbers & CType(GetGridCell(row, "lgh_number").Value, Integer) & comma
                    Session("data") = loadnumbers
                End If
            Next
        End If
    Catch ex As Exception
        Master.ShowMsg("", Message.Type.Error)
    End Try
End Sub

ok modified code to this

    Public Sub Check_Clicked(sender As Object, e As EventArgs)
    Dim loadnumbers As String = ""
    Const comma As Char = (",")
    Dim a As String
    Try
        If Session("data") IsNot Nothing Then
            For Each row As UltraGridRow In iuwgLoadGrid.Rows
                Dim myCellItem = GetGridCell(row, row.Index, "SELECTLOAD")
                Dim myCheckBox = DirectCast(myCellItem.FindControl("chkSelectLoad"), CheckBox)
                loadnumbers = loadnumbers & CType(GetGridCell(row, "lgh_number").Value, Integer)
                If (myCheckBox.Checked = True) Then
                    If Not Session("data").Contains(loadnumbers) Then
                        Session.Add(loadnumbers, ",")
                        a = Session("data")
                    End If
                End If
            Next
        Else
            For Each row As UltraGridRow In iuwgLoadGrid.Rows
                Dim myCellItem = GetGridCell(row, row.Index, "SELECTLOAD")
                Dim myCheckBox = DirectCast(myCellItem.FindControl("chkSelectLoad"), CheckBox)
                Dim data As String
                If (myCheckBox.Checked = True) Then
                    data = data & CType(GetGridCell(row, "lgh_number").Value, Integer) & comma
                    Session("data") = data
                End If
            Next
        End If
    Catch ex As Exception
        Master.ShowMsg("", Message.Type.Error)
    End Try
End Sub

Upvotes: 0

Views: 539

Answers (1)

user2792158
user2792158

Reputation: 11

Public Sub Check_Clicked(sender As Object, e As EventArgs)
    Dim loadnumbers As String = ""
    Dim data As List(Of String) = loadnumbers.Split(",").ToList()
    Dim myList As List(Of String) = DirectCast(Session("data"), List(Of String))
    'Const comma As Char = (",")
    Try
        If Session("data") IsNot Nothing Then
            For Each row As UltraGridRow In iuwgLoadGrid.Rows
                Dim myCellItem = GetGridCell(row, row.Index, "SELECTLOAD")
                Dim myCheckBox = DirectCast(myCellItem.FindControl("chkSelectLoad"), CheckBox)
                If (myCheckBox.Checked = True) Then
                    loadnumbers = CType(GetGridCell(row, "lgh_number").Value, Integer)
                    If Not myList.Contains(loadnumbers) Then
                        myList.Add(loadnumbers)
                    End If
                ElseIf (myCheckBox.Checked = False) Then
                    loadnumbers = CType(GetGridCell(row, "lgh_number").Value, Integer)
                    If myList.Contains(loadnumbers) Then
                        myList.Remove(loadnumbers)
                    End If
                End If
            Next
            Session.Add("data", myList)
        Else
            For Each row As UltraGridRow In iuwgLoadGrid.Rows
                Dim myCellItem = GetGridCell(row, row.Index, "SELECTLOAD")
                Dim myCheckBox = DirectCast(myCellItem.FindControl("chkSelectLoad"), CheckBox)
                If (myCheckBox.Checked = True) Then
                    loadnumbers = CType(GetGridCell(row, "lgh_number").Value, Integer)
                    data.Add(loadnumbers)
                End If
            Next
            Session("data") = data
        End If
    Catch ex As Exception
        Master.ShowMsg("", Message.Type.Error)
    End Try
End Sub

Upvotes: 1

Related Questions