Solved

Load Xml Data in Nested Gridview

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

26 Experts available now in Live!

Get 1:1 Help Now