Users Pricing

articles

XmlDataSource Control in ASP.Net

Pushpendra Singh 12786 04 Nov 2010 Updated 04 Mar 2020

XmlDataSource is usually used to display read only XML data.

<asp:XmlDataSource ID="XmlDataSource1" runat="server">
</asp:XmlDataSource>

Important properties of XmlDataSource Control

  •           Data: This property gets or sets the block of XML data that the XmlDataSource control binds to. We can bind XML data inline using this property. If both DataFile and Data properties are set, the DataFile property takes precedence and the data in the XML file is used instead of XML data specified in Data property.
  •           XPath: This property specifies an XPath expression which acts as filter the XML file contained by DataFile property or XML data specified by Data property.

Binding XMLDataSource to GridView

<asp:GridView ID="GridView1" runat="server" DataSourceID="XmlDataSource" 
            AutoGenerateColumns="False" ShowFooter="True">
        <Columns>
        <asp:TemplateField>
        <ItemTemplate>
   
      <%#XPath("@name") %><br />
      <%#XPath("State")%><br />
      <%#XPath("city")%><br /> </ItemTemplate>
 
        </asp:TemplateField>
        </Columns>
 </asp:GridView>
 <asp:XmlDataSource ID="XmlDataSource" runat="server"DataFile="~/XMLFile.xml"
 XPath="IranHistoricalPlaces/Place">
</asp:XmlDataSource>

XmlDataSource Control in ASP.Net

XmlDataSource Control in ASP.Net


Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md