我正在使用infragistics构建的自定义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
答案 0 :(得分: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