Listbox inside gridview

vbhargav80 used Ask the Experts™
Dear Experts,

I am using linq to SQL to bind my result to a gridview. I have a customers table and each customer can have multiple orders. When I query the customers table using linq, it should automatically return the list of orders for each customers as they have a foreign key relationship.

The problem is how do i bind my orders list to a listbox control inside a dridview column.

Can you please help? Followng is my code
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false">
        <asp:BoundField HeaderText="ID" DataField="ID" />
        <asp:BoundField HeaderText="Name" DataField="Name" />
        <asp:TemplateField HeaderText="Orders">
                <asp:ListBox ID="lstOrders" runat="server" DataSource="WHAT SHOULD GO HERE">
In codebehind this is how i bind
DBContext context = new DBContext ();
            var customers = from c in context.Customers
                          select new {c.Name, c.ID, c.Orders};
            gvCustomers.DataSource = customers ;

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Developer User Interface
U could handle the rowdatabound event of the gridview.

Write this code...

ListBox list = e.Row.FindControl("listboxname") as ListBox;

list.DataSource= ds;


Thanks so much!

Works Perfectly!!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial