Wednesday, November 18, 2009

Bind ArrayList Text and Value Field to DataList

Here is the code for binding the text and the value fields of the ArrayList to a DataList in using C#.

<asp:DataList ID="DataList1" runat="server">
<%# ((ListItem)Container.DataItem).Text %> ..........<%# ((ListItem)Container.DataItem).Value %>

Code behind:
ArrayList aa = new ArrayList();
aa.Add(new ListItem("John", "1"));
aa.Add(new ListItem("Smit", "2"));
aa.Add(new ListItem("Bob", "3"));
DataList1.DataSource = aa;

1 comment:

  1. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.
    html5 video player| html5 player