Skip to content

Checkbox value added to session.

New Discussion
jr
jr asked on Nov 7, 2013 11:48 AM

I have the following code looking I can retrieve the value of the check boxes. My problem is I getting all the values the one that are check and unchecked.

The String "lgh_number" is the DataKeyField

 Public Sub Check_Clicked(sender As Object, e As EventArgs)
        Dim checkBox As CheckBox = DirectCast(sender, CheckBox)
        Dim data As New List(Of String)()
        Try
            For Each item As UltraGridRow In iuwgLoadGrid.Rows
                If checkBox IsNot Nothing Then
                   If checkBox.Checked Then
                            If Session("data"IsNot Nothing Then
                                DirectCast(Session("data"), List(Of String)).Add(CType(GetGridCell(item, "lgh_number").Value, Integer))
                            End If
                            Session("data") = data
                        End If
 
                End If
                If checkBox.Checked Then
                    If Session("data"IsNot Nothing Then
                        DirectCast(Session("data"), List(Of String)).Remove(CType(GetGridCell(item, "lgh_number").Value, Integer))
                    End If
                    Session("data") = data
                End If
            Next
        Catch ex As Exception
 
        End Try
    End Sub

Now I have change code to look like this.
    Public Sub Check_Clicked(sender As Object, e As EventArgs)
        Dim tempCol As Infragistics.WebUI.UltraWebGrid.TemplatedColumn
        Dim checkBox As CheckBox
        Dim cObjs As ArrayList
        Dim data As New List(Of String)()
        Const comma As Char = (",")
        Dim cItems As Infragistics.WebUI.UltraWebGrid.CellItem
        Dim sChkName As String
        tempCol = iuwgLoadGrid.Rows(0).Cells(0).Column
        cObjs = tempCol.CellItems
       
        Try
            For Each item As Object In cObjs
                cItems = CType(item, Infragistics.WebUI.UltraWebGrid.CellItem)
                With cItems
                    sChkName = "chkSelectLoad" & .Cell.Row.Cells.FromKey("SELECTLOAD").Value
                    checkBox = .FindControl(sChkName)
                    If checkBox IsNot Nothing Then
                        If checkBox.Checked Then
                            For Each row As UltraGridRow In iuwgLoadGrid.Rows
                                DirectCast(Session("data"), List(Of String)).Add(CType(GetGridCell(row, "lgh_number").Value, Integer) & comma)
                                Session("data") = data
                            Next
                            'if this is checked then perform some function or store in an array or something.
                        End If
                    End If
                End With
            Next
        Catch ex As Exception
 
        End Try
    End Sub
This allow me to check if check is really check on the grid.
Yet when I try to add the value to session getting a object not reference error.


Ok here is the lastest changes it works, It find the check boxes that are check get the "lgh_number" the DataFieldKey. Stores it into a Session and checks for
duplicates. I have to reverse the process now to have the check boxes repopulate base on Page.

 Public Sub Check_Clicked(sender As Object, e As EventArgs)
        Dim tempCol As Infragistics.WebUI.UltraWebGrid.TemplatedColumn
        Dim checkBox As CheckBox
        Dim cObjs As ArrayList
        Dim data As ArrayList
        Dim loadnumbers As String = ""
        Const comma As Char = (",")
        Dim cItems As Infragistics.WebUI.UltraWebGrid.CellItem
        Dim sChkName As String
        tempCol = iuwgLoadGrid.Rows(0).Cells(0).Column
        cObjs = tempCol.CellItems
       
        Try
            For Each item As Object In cObjs
                cItems = CType(item, Infragistics.WebUI.UltraWebGrid.CellItem)
                With cItems
                    sChkName = "chkSelectLoad" & .Cell.Row.Cells.FromKey("SELECTLOAD").Value
                    checkBox = .FindControl(sChkName)
                    If checkBox IsNot Nothing Then
                        If checkBox.Checked Then
                            For Each row As UltraGridRow In iuwgLoadGrid.Rows
                                If LoadDetailsLogic.GetCheckBoxControlValueFromGrid(row, "SELECTLOAD""chkSelectLoad"Then
                                    loadnumbers = loadnumbers & CType(GetGridCell(row, "lgh_number").Value, Integer) & comma
                                    Session("data") = loadnumbers
                                End If
                            Next
                            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("checkboxdata") = data
                            Next
                        Else
                            For Each row As UltraGridRow In iuwgLoadGrid.Rows
                                If LoadDetailsLogic.GetCheckBoxControlValueFromGrid(row, "SELECTLOAD""chkSelectLoad"Then
                                    loadnumbers = loadnumbers & CType(GetGridCell(row, "lgh_number").Value, Integer) & comma
                                End If
                                Session.Contents.Remove(loadnumbers)
                            Next
                        End If
                    End If
                End With
            Next
        Catch ex As Exception
 
        End Try
    End Sub



Sign In to post a reply

Replies

  • 0
    Ivaylo Ganchev
    Ivaylo Ganchev answered on Oct 23, 2013 9:39 AM

    Hello Shelby and Welcome to the forum,

    I suggest On Page_Load iterate trough the rows and populate the checkboxes based on the session variable value for the corresponding row's checkbox.

    If you still have any concerns or questions I will be glad to help.

  • 0
    Ivaylo Ganchev
    Ivaylo Ganchev answered on Nov 7, 2013 11:48 AM

    Hello,

    I am checking about the progress of this issue.

    Could you solve your issue accordingly the information that I provided to you?

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
jr
Favorites
0
Replies
2
Created On
Nov 07, 2013
Last Post
12 years, 10 months ago

Suggested Discussions

Created by

jr

Created on

Nov 7, 2013 11:48 AM

Last activity on

Nov 7, 2013 11:48 AM