Unable to bind a column which in a list within a list


Joined
Mar 15, 2011
Messages
1
Reaction score
0
:congrats:Hello ,

I have the following code:

public class abc
{
public string customername { get; set; }
public List<def> DEF { get; set; }
}


public class def
{
public string materialcode { get; set; }
}

on page load

protected void Page_Load(object sender, EventArgs e)
{
List<abc> test1 = new List<abc>();
List<def> test2 = new List<def>();

test2.Add(new def() {materialcode="something" });
test1.Add(new abc(){customername="anything", DEF=test2});
GridView1.DataSource = test1;
GridView1.DataBind();
}

and in the ascx file


<asp:GridView ID="GridView1" runat="server">

<Columns>
<asp:TemplateField HeaderText="Charge Code">
<ItemTemplate>
<asp:Label ID="lblchargecode" runat="server" Text='<%#((def)Eval("DEF"))[0].materialcode %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>

I am getting an error message stating that def is not a member , if i am missing an assembly reference.

Please help me bind it to the gridview. Its very urgent

Thanks all.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top