Click here to Skip to main content
15,881,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a DataList control on my webpage, the rows of which are populated by ItemTemplate. Each row has a check box, and on button click, I am generating as a string which is actually a `sql` query text.

Each result returned by the query from the DB has 10 rows which are to be shown in another DataList, as something like this:

JavaScript
<Header>

Item1: Result1
Item2: Result2
Item3: Result3
...
Item10: Result10


The problem is that I do not know how many checkboxes will be selected by the user, and according the number of results returned will be unknown.
So, if the user selects two checkboxes from the first DataList, the result DataList should have two columns:

JavaScript
<Header1>                  <Header2>

Item1: Result1    | Item 1: ResultCol2
Item2: Result2    | Item 2: ResultCol2
Item3: Result3    | Item 3:ResultCol2
...
Item10: Result10 | Item 10: ResultCol2


I tried to think of a solution for this. Let's say a user selects two check boxes:

foreach checkbox selected by the user
    Make a new repeater. Add a new header. 
    Fetch the data from the database (Each result contains 10 columns) and bind to the repeater.
    Add the repeater to a container on the web page.

Now, I remember that in windows forms, such addition of runtime generated controls can be done by something like:

C#
TableLayout.Add(childElements)


But, I am not able to think of something similar in Web Forms. Is this actually the correct approach? How can this kind of dynamic building of DataControl achieved in this case?
How will I actually format the repeater as I would have done at design time with
HTML
<ItemTemplate>
etc.?
Posted
Updated 29-Feb-12 6:59am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900