dynamically generate checkboxlists (ASP .net 2.0 w/ C#)

Discussion in 'ASP .Net' started by KBuser, Apr 11, 2006.

  1. KBuser

    KBuser Guest

    I'm building an internal site which will allow for extremely
    customizable queries to be run against our SQL Server (2000) DB. The
    page is done in ASP .net 2.0, with C# code behind.
    The initial page has a checkboxlist which is generated from a query
    which returns all the user tables in our database. This is
    checkboxlistTables. For each table selected in this list I want to
    dynamically generate a new checkboxlist in a (HTML) table on the page.
    These new check lists query the database and display a checkbox for
    each column in the associated table.

    The way I'm doing it now is, I've simply created the 12 or 13
    checkboxlists (one for each table in our db) which query
    INFORMATION_SCHEMA.Columns to populate their lists. I simply make these
    listboxes visible when the appropriate check box is checked in
    checkboxlistTables. As you can imagine this entails a lot of redundant
    code, and will 'cause some problems down the road as tables are
    added/deleted. What I want to do is create an array (or something
    similar) of checkboxlists, which are generated and populated on the fly
    as needed. This is where I am stuck, as I've never done something like
    this, and am not sure how to proceed.

    At the moment I use something along the lines of:
    for (int i = 0; i < CheckBoxList0.Items.Count; i++)

    for each checkboxlist (CheckBoxList0 - CheckBoxList11) to see which
    columns from which tables needed to be included in my query. I'd like
    to be able to do something like:
    for (int i = 0; i < CheckBoxList[x].Items.Count;i++) inside of a larger
    loop which cycles through all of the generated listboxes. Is this
    possible? Any solutions/suggestions on generating these listboxes and
    cycling through them?

    Thanks in advance,
    KBuser, Apr 11, 2006
    1. Advertisements

  2. Brian

    Brian Guest

    This is very possible and I've done something similar for
    customer-defined properties. A couple of notes:

    1. I used an asp:placeholder control as the 'root' of the custom
    control list.
    2. you'll have to build your controls every time - not just the first
    time you hit the page. Otherwise the controls don't exist and asp.net
    won't know what to do with the form collection.
    3. You can then call placeholder.FindControl() for each of your custom
    controls to get its value.

    Hope that helps!

    Brian, Apr 11, 2006
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2FuZHk=?=

    Client side code for two checkboxlists

    =?Utf-8?B?U2FuZHk=?=, Jun 8, 2005, in forum: ASP .Net
    Jun 9, 2005
  2. Michael Groeger

    Validation of CheckBoxLists

    Michael Groeger, Sep 29, 2005, in forum: ASP .Net
    S. Justin Gengo
    Sep 29, 2005
  3. Pranav Shah

    DropDownLists, ListBoxs, and CheckBoxLists

    Pranav Shah, Jul 25, 2003, in forum: ASP .Net Web Controls
    Jul 25, 2003
  4. Mike Rogers

    problems with assigning specified indexes to checkboxlists

    Mike Rogers, Aug 9, 2003, in forum: ASP .Net Web Controls
    Mike Rogers
    Aug 9, 2003
  5. DJE2009

    nested checkBoxLists

    DJE2009, Jan 31, 2009, in forum: ASP .Net Web Controls
    Jan 31, 2009

Share This Page