Solved

Load Xml Data in Nested Gridview

Posted on 2006-10-23
4
933 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now