how to combining /reusing xmldatasource /xpath over several pages

Last post 07-02-2008 5:30 AM by Samu Zhang - MSFT. 1 replies.

Sort Posts:

  • how to combining /reusing xmldatasource /xpath over several pages

    06-28-2008, 5:34 AM

    Hi,

    I have about 10 pages which refer to 10 different courses. 

    Part of the xmldatasouce is the same in each page:  How do i recycle the datasource efficiently?

       <asp:XmlDataSource
            id="XmlSourceT1"
            DataFile="/courselist.xml"
            runat="server"
            XPath="courseList/category/product[@code ='av']" />

    The actual content is listed in the usercode file and is selected based on the "@code='something'" in the xpath.  I can see moving the datasource to the usercode.ascx.vb file but how do i change the code to reflect the page.

    so in pages:

    av.aspx =   XPath="courseList/category/product[@code ='av']" />

    lr.aspx =   XPath="courseList/category/product[@code ='lr']" />

    hr.aspx =   XPath="courseList/category/product[@code ='hr']" />

     

    etc.

    Thanks

    Tania

  • Re: how to combining /reusing xmldatasource /xpath over several pages

    07-02-2008, 5:30 AM
    Answer

    Hi taniafarmer ,

    So the xmlDataSource control reside in UserControl. You need to expose one public property , and you will set xmlDataSource's xpath manually.

     

        public string Xpath
        {
            
            set 
            {
                this.XmlDataSource1.XPath = "courseList/category/product[@code ='"+value+"']"; 
            }
        }
      
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl4.ascx.cs" Inherits="WebUserControl4" %>
    <asp:XmlDataSource ID="XmlDataSource1" runat="server"></asp:XmlDataSource>

     

     

    Sincerely,
    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter