Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > dynamically generate checkboxlists (ASP .net 2.0 w/ C#)

Thread Tools

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

Posts: n/a
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,

Reply With Quote
Posts: n/a
This is very possible and I've done something similar for
customer-defined properties. A couple of notes:

1. I used an asplaceholder 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
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!


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
nested checkBoxLists DJE2009 ASP .Net Web Controls 0 01-31-2009 01:22 AM
Validation of CheckBoxLists Michael Groeger ASP .Net 3 09-29-2005 03:53 PM
Client side code for two checkboxlists =?Utf-8?B?U2FuZHk=?= ASP .Net 2 06-09-2005 01:11 AM
problems with assigning specified indexes to checkboxlists Mike Rogers ASP .Net Web Controls 0 08-09-2003 10:46 AM
DropDownLists, ListBoxs, and CheckBoxLists Pranav Shah ASP .Net Web Controls 1 07-25-2003 08:51 AM