Help with getting two different data types from IEnumerable
I have IEnumerable
object with value1 and value2. value2 is an array and value1 is string.
I want to databind this object to Listview like that. So both value1 and value2[0] (开发者_运维百科always first item in array) could be accessed via <%# Eval("value1") %>
and <%# Eval("value2") %>
.
How to write expression to handle both items ?
ListViewItems.DataSource = f.Items.Select(t => t.value1, t.value2[0]);
ListViewItems.DataBind();
You should create an anonymous type:
ListViewItems.DataSource = f.Items.Select(
t => new { Value1 = t.value1, Value2 = t.value2[0] }
);
精彩评论