Home > DeveloperSection > Articles > XmlDataSource Control in ASP.Net

XmlDataSource Control in ASP.Net

Posted by  Pushpendra Singh
on    November-04-2010 16:27 PM

ADO.Net ADO.Net 
Ratings:
0 Comment(s)
 4330  View(s)
Rate this:

XmlDataSource Control in ASP.Net

XmlDataSource is usually used to display read only XML data.

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

</asp:XmlDataSource>

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">

        <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


Recent Activities

priyanka kushwaha added new Blog Friend function in C   12 hours ago


Maria Susan Created New Discussion Pass an object from controller to view with asp.net   21 hours ago

Jeet Verma added new Question What is negative infinity?   yesterday

Don't want to miss updates? Please click the below button!