Reputation: 31345
Is there a way to shorten the markup for this repeater? I am binding a DataTable to this repeater. It bothers me because ((System.Data.DataRowView)Container.DataItem) is repetitive and makes the markup less readable especially when you have more fields. I am using .Net 3.5 C# WebForms. MVC is not an option. Thanks.
<asp:Repeater ID="rDefinitions" runat="server">
<ItemTemplate>
<h3><%#((System.Data.DataRowView)Container.DataItem)["Name"]%></h3>
<p>Definition:
<%#((System.Data.DataRowView)Container.DataItem)["Definition"]%>
</p>
</ItemTemplate>
</asp:Repeater>
Upvotes: 1
Views: 270
Reputation: 6353
While this topic refers to .NET 3.5, .NET 4.5 now offers strong binding for Web Forms. MVC is not required. Set the ItemType field on the repeater and then use the form, Item.Data to reference fields.
Upvotes: 0
Reputation: 196
Why not use the simplified data binding statements introduced with ASP.NET 2.0?
Upvotes: 4
Reputation: 69993
You can import the System.Data namespace to leave off the System.Data part.
But as for the rest, I believe its necessary.
Upvotes: 1