Select property not set for Dynamic CheckBoxList

Last post 07-10-2007 12:50 PM by robnot. 5 replies.

Sort Posts:

  • Select property not set for Dynamic CheckBoxList

    07-10-2007, 12:27 PM
    • Loading...
    • robnot
    • Joined on 02-20-2007, 6:50 PM
    • Posts 99

    On my page, I'm filling in a CheckBoxList dynamically based on different user interactions.

            CheckBoxList1.DataSource = cmd.ExecuteReader
            CheckBoxList1.DataTextField = "name"
            CheckBoxList1.DataValueField = "subgroup_id"
            CheckBoxList1.DataBind()

     The values fill in the list, but when I submit the form the checkboxes don't show up as being selected.

        Dim cli As ListItem
        For Each cli In CheckBoxList1.Items
            If cli.Selected Then
                Response.Write("I've been selected:" + cli.Value.ToString + "<br />")
            Else
                Response.Write("I haven't been selected: " + cli.Value.ToString + "<br />")
            End If
        Next
     (in the case of this test code, I get back only "I haven't been selected" messages)

     Is there an error in my method? Is there something I'm missing? Is there a different way of doing this?

     

  • Re: Select property not set for Dynamic CheckBoxList

    07-10-2007, 12:34 PM
    Answer
    • Loading...
    • joteke
    • Joined on 06-16-2002, 3:24 PM
    • Kyro, Finland
    • Posts 6,568
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    Do you populate the list  intiially in If Not Page.IsPostBack Then .... check. I'm after that you don't initialize the selections by redatabinding the list

    Thanks,

    Teemu Keiski
    Finland, EU
  • Re: Select property not set for Dynamic CheckBoxList

    07-10-2007, 12:35 PM
    • Loading...
    • ps2goat
    • Joined on 11-17-2006, 5:43 PM
    • Posts 1,651

    Build and rebuild you checkboxlist in Page_Init.  This will allow ViewState to be loaded for the control, which recreates the dataview that the client had (including checked items).

     

    (Never mind my post if you aren't building and adding the checkboxlist control dynamically.  I think I read the question with a bit of dyslexia.)

    ---------------------------------------
    MCP - Web Based Client Development .NET 2.0
  • Re: Select property not set for Dynamic CheckBoxList

    07-10-2007, 12:41 PM
    • Loading...
    • robnot
    • Joined on 02-20-2007, 6:50 PM
    • Posts 99

    How would I go about doing that? Do I just put all the databinding into the Page_Init event handler or is there more?

  • Re: Select property not set for Dynamic CheckBoxList

    07-10-2007, 12:45 PM
    • Loading...
    • robnot
    • Joined on 02-20-2007, 6:50 PM
    • Posts 99

    I populate the list initially using a method called from Page_Load, this method handles filling in the content of the CheckBoxList in all cases.

  • Re: Select property not set for Dynamic CheckBoxList

    07-10-2007, 12:50 PM
    • Loading...
    • robnot
    • Joined on 02-20-2007, 6:50 PM
    • Posts 99

    Duh, it's always the simplest things that become the most confounding.  Thanks! 

Page 1 of 1 (6 items)
Microsoft Communities
Page view counter