XmlDataSource is usually used to display read only XML data.

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

Important properties of XmlDataSource Control

  • DataFile: This property allows specifying the name of XML file that the XmlDataSource control binds to. You can specify either absolute file path or relative file path of XML file.
  •           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">
      <%#XPath("@name") %><br />
      <%#XPath("State")%><br />
      <%#XPath("city")%><br /> </ItemTemplate>
 <asp:XmlDataSource ID="XmlDataSource" runat="server"DataFile="~/XMLFile.xml"

XmlDataSource Control in ASP.Net

XmlDataSource Control in ASP.Net

  Modified On Sep-07-2019 12:11:31 AM

Leave Comment