SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2008
    Location
    Morristown, NJ
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamically creating Checkboxlist in .NET 2.0

    I'm having a problem dynamically populating a checkboxlist control. The checkboxlist control is simple:

    <asp:CheckBoxList id="thisCompanyList" runat="server" />

    And here's the VB code to populate it from a database loop:

    thisCompanyList.Items.Add(new ListItem(myReader("CompanyName").ToString(), myReader("CompanyID").ToString()))

    I was under the impression this is the method to populate a checkbox (or radio) list - did this change in .NET 2.0 that I'm not aware of?

    control.Items.Add(new ListItem("Text", "Value"))

    The problem I am having is my code populates both the text and value with whatever text I put first, so I know it's not a SQL select problem. If I list the company Name first, both the value and text are the company Name. If I list the company ID, then both the value and text for the checkboxes are the ID. So I am properly pulling the values from the database. The problem is with the syntax I am using to populate the text and value fields for the checkbox. Any help is appreciated, tia~!

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2008
    Location
    Morristown, NJ
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I found the problem -- it was (of course) just a bug in my code elsewhere. On parsing the submitted results of the checkboxlist I was pulling thisCompanyList.Items(i).Text instead of thisCompanyList.Items(i).Value.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •