locked
Assistance with Checkboxlist RRS feed

  • Question

  • User-1320770751 posted

    Hi,

     

    I have a checkbox list, with about 13 + Items to select..... What I want to do, is when I click on the 4th item, it pops up another checkboxlist, giving it further choices. But when I unselect it, I wantthe "newly" appeared checkboxlist to dissapear..... but It gives me an error saying "Cannot convert String"" to double"

     

    The code I use is,

    If Chkboxlist1.selectedvalue = 4 then

    chkboxlist2.visible = true

    else

    chkboxlist2.visible = false

    end if

     

    Could comeone please assist me, thank you

    Wednesday, May 21, 2008 9:56 AM

Answers

  • User418373899 posted

    try placing brackets around the value ie

    If Chkboxlist1.selectedvalue = "4" then

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 21, 2008 10:29 AM

All replies

  • User418373899 posted

    try placing brackets around the value ie

    If Chkboxlist1.selectedvalue = "4" then

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 21, 2008 10:29 AM
  • User418373899 posted

    if you are trying to determine the index of the slect item in the list you need to use

     CheckBoxList1.SelectedIndex other use selectedvalue but this defaultly return a STRING which is why you are facing the issue you have

    Wednesday, May 21, 2008 10:34 AM
  • User1693635062 posted

    I was able to add and remove checkBoxes dynamicly with the following code... but I'm not sure if this is what you're looking for. PLUS there's a small bug in my code where if you click anywhere it will remove the last checkBox. easily fixed but I thought this could help you in what you wanted to do ...

    make sure your checkBoxlList control has it's AutoPostBack = TRUE

    Protected Sub CBL_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CBL.SelectedIndexChanged

    Dim currentPosition As Integer = 0

    Dim cbName As Integer = 0

    Try

                   If CBL.Items.Count > 1 Then

                            currentPosition = CBL.Items.Count - 1

                   End If

                   If CBL.Items(currentPosition).Selected Then

                           cbName += 1

                           CBL.Items.Add(
    "CheckBox" & cbName)

                   ElseIf CBL.Items.Count > 0 And CBL.Items(currentPosition).Selected = False Then

                           CBL.Items.RemoveAt(currentPosition)

                   End If

    Catch ex As Exception

    MsgBox(ex.Message)

    End Try

    Wednesday, May 21, 2008 10:38 AM