Repeater Data Control of ASP.Net 2.0 can also display the value stored in C# String Array. You can pass the Array name to the Repeater DataSource property for binding the data stored in string array. Simply Container.DataItem can be used in the ItemTemplate of Repeater control to display the items. Repeater Control displays the C# string array items as a horizontal list. You can use CSS style properties, div layout, HTML ul, ol and li tags or HTML table layout to display the array items in Repeater Control ItemTemplate. Repeater Control consumes much less memory than ASP.Net GridView and DataList control while rendering the items on ASP.Net web page. Repeater control’s iterative behavior to generate items can be used to generate list items or table rows dynamically. You can also see the examples of ASP.Net Repeater Table or ASP.Net Repeater Div Layout.
<ItemTemplate>
</asp:Repeater>
You can see that there is nothing special in the HTML source code to display Array Items in Repeater Control ItemTemplate. <%# Container.DataItem %> is used to call the item from the iteration process of Repeater Control. HTML <br /> tag is used to display each item in new line. Repeater Control will put <br /> tag after each item due to its iterative behavior.
string[] arr1 = new string[] { "array item 1", "array item 2", "array item 3", "array item 4", "array item 5" };
Repeater1.DataSource = arr1;
Repeater1.DataBind();
Name of string array arr1 is passed to the DataSource property of the Repeater control.
HTML Output:
<div>
array item 1<br />
array item 2<br />
array item 3<br />
array item 4<br />
array item 5<br />
</div>
Be the first to rate this post
Tags: asp.net 2.0, c# code, asp.net repeater control, asp.net string array, repeater container.dataitem, asp.net repeater table, c# repeater div layout, c# tutorials, repeater itemtemplate, asp.net repeater datasource, c# string array, asp.net repeater ul li
8/23/2008 8:43:49 PM