0

我正在作为使用基础设施构建的自定义 Webgrid 工作。我能够遍历行以到达复选框并将作为检查值的框存储到会话中。

这就是现在正在发生的事情。在任何页面上,我单击四个复选框将状态更改为 true。当我转到下一页并返回上一页时,我有一个方法可以根据值重新填充复选框并将这些框设置为 true。该方法有效

问题是当我在任何页面上单击我的框时,转到下一页单击其他框,返回上一页未选中框。但是,如果我转到下一页,我的框就会被选中。

需要的帮助是将多个页面中的复选框选中值保存到会话中。

 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

好的修改代码到这个

    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
4

1 回答 1

1
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
于 2013-09-23T03:24:48.503 回答