Reputation:
I have a <asp:Repeater>
control and I am binding a DataSet
to it with a number of different DataTables
.
I'm confused as to how to access and bind one table at time to my repeater.
I would like to do something like this
<ItemTemplate>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "heading_id") %>' />
</td>
</tr>
</ItemTemplate>
...but first for the table one then a new <tr>
and then data from the table two and so on.
Upvotes: 2
Views: 1639
Reputation: 40393
Sounds like you want nested repeaters, with the outside one representing the DataSet's DataTables, and the inside one representing the rows within a DataTable.
Personally, I've found nested repeaters to be horrible to work with because of the custom data binding, and unless you're doing a lot of event binding, I'd probably go with a more inline approach, something like the following:
<% foreach (var dt in MyDataSet.Tables) { %>
<table>
<% foreach (var row in dt.Rows) { %>
<tr>
<td><label><%= row["heading_id"] %></label></td>
</tr>
<% } %>
</table>
<% } %>
In your code-behind, you'd just need to assign your DataSet object to a protected field or property.
Upvotes: 1