Using XMLDataSource control in ASP.net


In this article I'm trying to explain how to work with <b>XMLDataSource</b> control for displaying database data to our DataControls. During this process we can able to learn how to configure LinqDataSource control and how to connect with DataControl. This is very simple to communicate with our Database.

Using XMLDataSource control in ASP.net:



In this article I'm trying to explain how to work with XMLDataSource control for displaying database data to our DataControls. During this process we can able to learn how to configure LinqDataSource control and how to connect with DataControl. This is very simple to communicate with our Database.

Follow below steps to configure XMLDataSource control in our Application.

Step-1:



Add an XML file in the solution explorer by right click on the project then choose XML File option in the list and give a name for that as employee.xml and then click on Add button a new XML file has been created under the project folder.

1

Step-2:



Open that xml file and design that like below manner.

<?xml version="1.0" encoding="utf-8" ?>
<employee>
<emp Name="Naveen" Id="1" Sal="15000"></emp>
<emp Name="Karthi" Id="2" Sal="20000"></emp>
<emp Name="Pawan" Id="3" Sal="25000"></emp>
</employee>


Step-3:



Drag and drop XMLDataSource control on the design view of the webpage then click on the smart tag to configure DataSource.

2

Step-4:



Then a new popup window will appear for configure XMLDataSource purpose. Choose DataFile available in the project and then click on OK button.

3

Step-5:



After adding the XML file then click on Ok button to configure XMLDataSource.

Step-6:



Now, XML Configuration process has been completed successfully, now simply drag & drop gridview control to the design view of the page and then choose XMLDataSource from Choose Data Source dropdown then click on Ok button then see the Gridview control changes.

4

Step-7:



See the Source code part of Gridview control, how it was configure in source.

<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/ASPnet/employee.xml"></asp:XmlDataSource>
<br />


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

DataSourceID="XmlDataSource1"

>
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" />
<asp:BoundField DataField="Sal" HeaderText="Sal" SortExpression="Sal" />
</Columns>
</asp:GridView>


Step-8:



Now, the times to check the output result just press F5 on keyboard and see the result.

5

Conclusion:



I hope this article will help you those who are looking for the same and those who are new to implement XMLDataSource control in your applications.

About Author:



This is Naveen, I completed my MCA and I have around 3 years of experience in ASP.net while implement Web Applications. For past 3 years I learn no.of Technologies while implement my applications apart from that I try to learn new technologies and I try to implement that while implement my project.


Article by naveensanagasetti
I hope you enjoyed to read my article, If you have any queries out of this then please post your comments.

Follow naveensanagasetti or read 139 articles authored by naveensanagasetti

Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: