views:

327

answers:

1

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>
A: 

Try this:

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

dl
Thank you! And when we want two-way binding?<%# Bind(Container.DataItem) %>doesn't work :(
Sevina
It's a good question, and I'm not sure what the answer is. You might want to consider using a generic list of KeyValuePairs or Dictionaries.
dl