Reputation: 2089
I have a Repeater control who has its dataSource setted with a typed object list and in the inline code I want to access to its elements properties inside the ItemTemplate tag. I tried this with the eval expression but it does not work:
<ItemTemplate>
<tr>
<td><%# Eval("code") %></td>
<td><%# Eval("description") %></td>
</tr>
</ItemTemplate>
Any ideas?
Thank you!!
Upvotes: 0
Views: 896
Reputation: 44268
Does your object have a property called "code". Remember it's case sensitive.
e.g. If your object were...
public class MyObj
{
public string Code { get; set; }
public string Description { get; set; }
}
And you were binding a Collection<MyObj>
to your datasource,
Then you're repeater would look like...
<asp:repeater id="Repeater1" runat="server">
<headertemplate>
<table border="1">
<tr>
<td><b>Code</b></td>
<td><b>Description</b></td>
</tr>
</headertemplate>
<itemtemplate>
<tr>
<td> <%# Eval("Code") %> </td>
<td> <%# Eval("Description") %> </td>
</tr>
</itemtemplate>
<footertemplate>
</table>
</footertemplate>
</asp:repeater>
Upvotes: 0
Reputation: 13214
You can use: <%# DataBinder.Eval(Container.DataItem, "field name") %>
Upvotes: 2