eugeneK
eugeneK

Reputation: 11146

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();

Upvotes: 0

Views: 329

Answers (1)

SLaks
SLaks

Reputation: 888205

You should create an anonymous type:

ListViewItems.DataSource = f.Items.Select(
    t => new { Value1 = t.value1, Value2 = t.value2[0] }
);

Upvotes: 2

Related Questions