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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top