Tuesday, 20 April 2010

Binding List<String > or String Array to Repeater

<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<%# Container.DataItem %>
<br />
</ItemTemplate>
</asp:Repeater>

You can see that there is nothing special in the HTML source code to display Array Items in Repeater Control ItemTemplate. Instead of something like
<%# DataBinder.Eval(Container.DataItem, "Price", "{0:c}") %>
<%# Container.DataItem %>

is used to call the item from the iteration process of Repeater Control. Because here Container.DataItem itself is the item to display, not something within the Container.DataItem.

string[] arr1 = new string[] {"array item 1","array item 2", };
Repeater1.DataSource = arr1;
Repeater1.DataBind();

No comments:

Post a Comment