Bind List of object array to ListView in ASP.NET

asp.net, bind, eval, listview

Solution

Your datasource is not capable for standard databinding. Convert it to a name value pair, which will have a name and a value for each item that will be binded. For example Dictionary<string, string> collection is compatible for this. And then just turn your ListView to this :

<asp:Label runat="server" ID="lblId"
    Text='<%# Eval("Key") %>'></asp:Label>

<asp:Label runat="server" ID="lblName"
    Text='<%# Eval("Value") %>'></asp:Label>

Problem

I am breaking my head to fix an issue. I have a method that returns a `List<Object[]>`. Each `object[]` in the List contains the following: ``` object[0]=Id; object[1]=Name; ``` Now, I am looking for a way to bind this List to a ListView in a custom `ItemTemplate` which would look as follows: ``` <asp:Label runat="server" ID="lblId" Text="Here want to do an Eval/Bind for object[0]"></asp:Label> <asp:Label runat="server" ID="lblName" Text="Here want to do an Eval/Bind for object[1]"></asp:Label> ``` Any suggestions will be deeply appreciated.

Original source