dynamically generate checkboxlists (ASP .net 2.0 w/ C#)
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,
Re: dynamically generate checkboxlists (ASP .net 2.0 w/ C#)
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
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!
|All times are GMT. The time now is 09:18 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.