Solved

Load Xml Data in Nested Gridview

Posted on 2006-10-23
4
937 Views
Last Modified: 2012-06-27
Hi,

I have a nested Gridview (a Gridview within a Gridview), which is from a customers table.  The main Gridview lists the customer's name and the nested Gridview is to list the related products for the customer, which is stored as xml within the database table.  The code takes the following form (formatting, etc. removed):

<asp:GridView id="Customers" runat="server">
  <Columns>
    <asp:TemplateField>
      <ItemTemplate>
        <table>
          <tr>
            <td>
              <asp:Label id="Customer" runat="server"><%# DataBinder.Eval(((GridViewRow)Container).DataItem, "Customer") %></asp:Label>
            </td>
          </tr>
          <tr>
            <td>
              <asp:XmlDataSource id="xxmlData" runat="server" EnableCaching="false"></asp:XmlDataSource>
              <asp:GridView id="Products" runat="server">
                <Columns>
                  <asp:TemplateField>
                    <ItemTemplate>
                      <table>
                        <tr>
                          <td>
                            <asp:Label id="Product" runat="server"><%# XPath("Product") %></asp:Label>
                          </td>
                          <td>
                            <asp:ImageButton id="ProductLink" runat="server" CommandName='<%# XPath("ProductID") %>' OnClick="View" />
                          </td>
                        </tr>
                      </table>
                    </ItemTemplate>
                  </asp:TemplateField>
                </Columns>
              </asp:GridView>
            </td>
          </tr>
        </table>
      </ItemTemplate>
    </asp:TemplateField>
  </Columns>
</asp:GridView>

Does anyone know how I can load the Xml data into the nested Gridview via the XmlDataSource?

Thanks,

John
0
Comment
Question by:ukinet
4 Comments
 
LVL 21

Accepted Solution

by:
MogalManic earned 500 total points
ID: 17787707
iN YOUR Page_Load() just locate your XML datasource
  XmlDataSource source=  Customers.FindControl("xxmlData") as XmlDataSource;

and set its Data property:
  source.Data=xml;
  source.DataBind();

Don't forget to set the DataSourceID to xxmlData in the gridview:
  <asp:GridView id="Products" runat="server" DataSourceID="xxmlData">

You can simplify the programming if you put the datasource outside of the parent gridview.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question