locked
I have a vb.net application that has eight checkboxes for the user to select a 'job type'. The aspx code is below: RRS feed

  • Question

  • User1539907945 posted
                        <asp:CheckBoxList AutoPostBack="true" ID="JobTypeCheckBoxList" runat="server" DataSourceID="SqlDataSource2"
                            CssClass="floatleft" RepeatLayout="Flow" CellSpacing="1" ToolTip="JobType" DataTextField="TYPE"
                            DataValueField="TYPE" RepeatDirection="Horizontal" Font-Bold="true">
                        </asp:CheckBoxList>
    

    The VB.Net code for the check boxes is below. The problem is JobTypeCheckBoxList.Items  shows 0 values. There should be 8 values.

        Sub SetJobTypeFilter()
            ' Creates the job type filter based on checked boxes.
            ' Need to call this subroutine anytime the visible month changes to make sure filter is properly applied before the calendar day render
            System.Diagnostics.Debug.WriteLine("SetJobTypeFilter() ")
            System.Diagnostics.Debug.WriteLine("JobTypeFilterString OLD VALUE: " & Session("JobTypeFilter"))
    
            JobTypeFilterString = ""
            JobTypeList.Clear()
    
            For Each checkBox As ListItem In JobTypeCheckBoxList.Items
                If (checkBox.Selected) Then
                    JobTypeList.Add(UCase(checkBox.Value))
                    If JobTypeFilterString = "" Then
                        JobTypeFilterString = JobTypeFilterString + checkBox.Value.ToString
                    Else
                        JobTypeFilterString = JobTypeFilterString + ", " + checkBox.Value.ToString
                    End If
                End If
            Next
            System.Diagnostics.Debug.WriteLine("JobTypeFilterString NEW VALUE: " & JobTypeFilterString)
            UpdateProfile("JobTypeFilter", JobTypeFilterString)
            Session("JobTypeFilter") = JobTypeFilterString
    
            SetFilterIndicator()
        End Sub
        Sub CheckJobTypeFilterBoxes()
            ' checks JobTypeCheckBoxList checkboxes based on session value loaded in global.asax when session starts
            System.Diagnostics.Debug.WriteLine("CheckJobTypeFilterBoxes()")
            System.Diagnostics.Debug.WriteLine("Session(""JobTypeFilter""): " & Session("JobTypeFilter").ToString)
    
            JobTypeList.Clear()
            If Not IsNothing(Session("JobTypeFilter")) Then
                JobTypeFilterString = Session("JobTypeFilter")
    
                Dim tempArray As Array = Split(UCase(JobTypeFilterString), ", ")
                Dim top As Integer = tempArray.Length - 1
    
                For x = 0 To top
                    JobTypeList.Add(tempArray(x))
                Next
    
                For Each checkBox As ListItem In JobTypeCheckBoxList.Items
                    If JobTypeList.Contains(UCase(checkBox.Value.ToString)) Then
                        checkBox.Selected = "True"
                    End If
                Next
            Else
    
                JobTypeFilterString = ""
            End If
            Session("JobTypeFilter") = JobTypeFilterString
    
            SetFilterIndicator()
        End Sub
    



    Wednesday, November 27, 2013 10:36 AM

Answers

  • User3690988 posted

    What are you trying to accomplish, load the values of the CheckBoxList into the JobTypeList?  If so, you can do something like this:

        JobTypeList.Clear()
        For I As Int16 = 0 To JobTypeCheckBoxList.Items.Count - 1
          If JobTypeCheckBoxList.Items(I).Selected Then
            JobTypeList.Add(JobTypeCheckBoxList.Items(I).Value)
          End If
        Next



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, November 27, 2013 6:07 PM