---
title: "XmlDataSource Control in ASP.Net"  
description: "XmlDataSource is usually used to display read only XML data.  aspXmlDataSource ID=\"XmlDataSource1\" runat=\"server\"  aspXmlDataSourceImportant properti"  
author: "Pushpendra Singh"  
published: 2010-11-04  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/191/xmldatasource-control-in-asp-dot-net  
category: "ado.net"  
tags: ["ado.net"]  
reading_time: 1 minute  

---

# XmlDataSource Control in ASP.Net

XmlDataSource is usually used to display read only [XML data](https://www.mindstick.com/forum/131/problem-in-showing-the-xml-data-in-well-formed).\

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

**Important [properties](https://yourviews.mindstick.com/view/81845/now-it-s-possible-to-predict-properties-of-any-molecule) of XmlDataSource Control**

- DataFile: This [property](https://www.mindstick.com/articles/198559/an-ownership-of-property-in-hua-hin) allows specifying the name of [XML file](https://www.mindstick.com/articles/75/how-to-read-and-write-xml-file-through-c-sharp) that the XmlDataSource control binds to. You can specify either [absolute](https://www.mindstick.com/interview/1159/what-is-absolute-and-sliding-expiration-in-dot-net) [file path](https://www.mindstick.com/forum/161592/how-do-you-validate-whether-a-given-path-is-a-valid-file-path-or-not) or [relative](https://answers.mindstick.com/qa/105067/how-to-trade-with-the-relative-vigor-index) 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](https://www.mindstick.com/blog/181/lambda-expression-in-c-sharp) which [acts as](https://answers.mindstick.com/qa/51373/what-were-president-johnson-s-first-official-acts-as-president) filter the XML file contained by DataFile property or XML data specified by Data property.

**Binding XMLDataSource to [GridView](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net)**

```
<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](https://www.mindstick.com/mindstickarticle/63f98132-d931-41bd-bb16-37c0967a25e8/images/7c72c419-5a7c-40ce-beaa-03be7ee5612e.png)

## ![XmlDataSource Control in ASP.Net](https://www.mindstick.com/mindstickarticle/63f98132-d931-41bd-bb16-37c0967a25e8/images/5fbd864c-1e56-4bf7-b151-19bad016af37.png)

---

Original Source: https://www.mindstick.com/articles/191/xmldatasource-control-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
