0

I have to generate DataLists at runtime according to the items selected by the user.

How can this be done from the .aspx code-behind? I have a fixed HeaderTemplate and ItemTemplate format for each of the DataList that will be generated.

<HeaderTemplate>
<tr>Table Heading<tr>
<tr>    <th>ItemNo</th> <th>Item Detail</th><tr>
</HeaderTemplate>

<ItemTemplate>
<tr>    <td><%#CallFunc()%></td>    <td><%#Eval("Item1")%></td> </tr>
<tr>    <td><%#CallFunc()%></td>    <td><%#Eval("Item2")%></td> </tr>
<tr>    <td><%#CallFunc()%></td>    <td><%#Eval("Item3")%></td> </tr>
<tr>    <td><%#CallFunc()%></td>    <td><%#Eval("Item4")%></td> </tr>
<tr>    <td><%#CallFunc()%></td>    <td><%#Eval("Item5")%></td> </tr>
<tr>    <td><%#CallFunc()%></td>    <td><%#Eval("Item6")%></td> </tr>
<tr>    <td><%#CallFunc()%></td>    <td><%#Eval("Item7")%></td> </tr>
<tr>    <td><%#CallFunc()%></td>    <td><%#Eval("Item8")%></td> </tr>
<tr>    <td><%#CallFunc()%></td>    <td><%#Eval("Item9")%></td> </tr>
<tr>    <td><%#CallFunc()%></td>    <td><%#Eval("Item10")%></td>    </tr>
<tr>    <td><%#CallFunc()%></td>    <td><%#Eval("Item11")%></td>    </tr>
</ItemTemplate>

A small example of this kind of runtime datalist generation, and assigning these templates to it would be greatly helpful.
Thanks

Cipher
  • 5,894
  • 22
  • 76
  • 112

1 Answers1

0

Why can not you use gridview?

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False">
        <Columns>
            <asp:BoundField DataField="ItemID" HeaderText="Item ID" />
            <asp:BoundField DataField="ItemName" HeaderText="Item Name" />
        </Columns>
    </asp:GridView>
PraveenVenu
  • 8,217
  • 4
  • 30
  • 39
  • Can I assign the templates to grid views as in the post above in the `code-behind`? – Cipher Mar 01 '12 at 14:47
  • Can this be done in code-behind? Can you post a small example of this generation? – Cipher Mar 01 '12 at 14:49
  • Screenshot I made for this thingg: http://i.imgur.com/t0elz.png Can you give some idea about how to do this? – Cipher Mar 01 '12 at 15:01
  • @PraveenMenu: Can I keep a grid on the web page, and keep on adding data to in columns in some kind of above format? Is that possible? – Cipher Mar 01 '12 at 15:31
  • I don't think I understand it fully. So the number of columns are dynamic? – PraveenVenu Mar 01 '12 at 16:02
  • @PraveenMenu: Yes, for each option checked by the user, a new column has to be generated. Or if you could any apporach to go for to use the above format i.e each column in the data control should have one queries result. – Cipher Mar 01 '12 at 16:06
  • @PraveenMenu: I am just starting out with ASP.NET. An example would be of great help for this – Cipher Mar 01 '12 at 16:32
  • try this friend http://stackoverflow.com/questions/1220715/creating-a-nested-repeater-control-dynamically – PraveenVenu Mar 01 '12 at 17:36
  • @PraveenMenu: How will this go into two columns then in case of a nested repeater? – Cipher Mar 01 '12 at 17:55
  • Set RepeatColumns property of the repeater to 2 and the RepateDirection to Horizontal – PraveenVenu Mar 01 '12 at 17:57
  • @PraveenMenu: TRying now. But doesn't 2 limit the number of columns to 2 only? What if the user selects three options from checboxes? – Cipher Mar 01 '12 at 18:00
  • @PraveenMenu: I don't think there is a RepeaterColumns property in the repater. Should I use DataList instead? – Cipher Mar 01 '12 at 18:06
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/8410/discussion-between-cipher-and-praveenvenu) – Cipher Mar 01 '12 at 18:07