views:

86

answers:

2

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>
+1  A: 

You can import the System.Data namespace to leave off the System.Data part.

<%@ Import Namespace="System.Data"%>

But as for the rest, I believe its necessary.

Brandon
thanks, never thought about adding namespaces in the aspx file
James Lawruk
+4  A: 

Why not use the simplified data binding statements introduced with ASP.NET 2.0?

<%# Eval("Name") %>

<%# Eval("Definition") %>

Wulfbane
thanks, this was helpful
James Lawruk