Reputation: 363
I'm working on a product using ASP.net / vb.net.
What I need to do is represent a matrix of locations vs products and select which products are available in which locations by using a grid of checkboxes.
The products are provided via a table (ProductID, ProductName) as are locations (LocationID, LocationName) and I have a Many to Many table (ID, ProductID, LocationID). The issue I'm stuck with is how to create a gridview with dynamic columns and rows based on separate data sources.
Am I being really stupid here? (actually, don't answer that!)
Any help would be greatly appreciated.
Thanks,
Steve
Upvotes: 0
Views: 101
Reputation: 590
There are two ways to do this :
Use a repeater control
Pivot the table at database end and bind it to gridview normally.
Upvotes: 2
Reputation: 4061
You can use nested Gridviews:
<asp:GridView ID="Products" runat="server">
<Columns>
<asp:BoundField DataField="ProductId" />
<asp:BoundField DataField="ProductName" />
<asp:TemplateField>
<ItemTemplate>
<asp:GridView ID="Locations" runat="server">
<Columns>
<asp:BoundField DataField="LocationId" />
<asp:BoundField DataField="LocationName" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The Products gridview has a TemplateField with a gridview Locations inside.
Upvotes: 1