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:
<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:
<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:
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
<ItemTemplate>
etc.?