0

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

Steve McCall
  • 363
  • 3
  • 6
  • 12
  • 1
    If u want to use `gridview` for data display purpose only ? I think `Repeter` is batter and faster .... see link http://stackoverflow.com/questions/3356229/nested-repeater – Anant Dabhi Apr 02 '15 at 11:50
  • I want to be able to have check boxes at each intersection to select if a product is in a location. Can I do that with a repeater? I've not used one before. – Steve McCall Apr 02 '15 at 13:31
  • yes you can do..all opration.. – Anant Dabhi Apr 02 '15 at 13:33

2 Answers2

2

There are two ways to do this :

  1. Use a repeater control

  2. Pivot the table at database end and bind it to gridview normally.

rohit singh
  • 550
  • 1
  • 11
  • 32
1

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.

enb081
  • 3,831
  • 11
  • 43
  • 66