List as DataSource for DataList

Sevina picture Sevina · Dec 7, 2009 · Viewed 9.9k times · Source

All Types implement IEnumerable interface could be used for a DataSource of a DataList. For example List. But what we will write for the data bound expression in ItemTemplate?

List<int> myList = new List<int>();
for(int i=0; i<10; i++)
   myList.Add(i);

myDataList.DataSource = myList;

...
<ItemTemplate>
<asp:TextBox ID="myTextBox" runat="server" Text='<%# Bind(???) %>' />
</ItemTemplate>

Answer

dl. picture dl. · Dec 7, 2009

Try this:

<%# Container.DataItem.ToString() %>