Solved

Load Xml Data in Nested Gridview

Posted on 2006-10-23
4
938 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…

697 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