Blue Theme Orange Theme Green Theme Red Theme
 
Discover the top 5 tips for understanding .NET Interop
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Discover the top 5 tips for understanding .NET Interop
Search :       Advanced Search »
Home » ASP.NET Controls » Xml DataSource control in ASP.NET 3.5

Xml DataSource control in ASP.NET 3.5

In this article I am going to discuss how to use XmlDataSource control in ASP.NET 3.5

Author Rank :
Page Views : 30728
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Nevron Chart
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


The XmlDataSource control is a data source control that presents XML data to data-bound controls. The XmlDataSource control can be used by data-bound controls to display both hierarchical and tabular data. The XmlDataSource control is typically used to display hierarchical XML data in read-only scenarios. Because the XmlDataSource control extends the HierarchicalDataSourceControl class, it works with hierarchical data. The XmlDataSource control also implements the IDataSource interface and works with tabular, or list-style, data.

The XmlDataSource typically loads XML data from an XML file, which is specified by the DataFile property. XML data can also be stored directly by the data source control in string form using the Data property. If you want to transform the XML data before it is displayed by a data-bound control, you can provide an Extensible Sylesheet Language (XSL) style sheet for the transformation. As with the XML data, you typically load the style sheet from a file, indicated by the TransformFile property, but you can also store it in string form directly using the Transform property.

The XmlDataSource control is commonly used in read-only data scenarios where a data-bound control displays XML data. However, you can also use the XmlDataSource control to edit XML data. To edit the XML data, call the GetXmlDocument method to retrieve an XmlDataDocument object that is an in-memory representation of the XML data. You can use the object model exposed by the XmlDataDocument and XmlNode objects it contains or use an XPath filtering expression to manipulate data in the document. When you have made changes to the in-memory representation of the XML data, you can save it to disk by calling the Save method.

Let's start now by diagrams :

First of all make a new ASP.NET Website using Microsoft Visual Studio 2008, like Figure1.

 
Figure1.

Now drag and drop a XmlDataSource and a TreeView control from toolbox.

 
Figure2.

Now add a new XML file in your solution sile.

 
Figure3.

Now this is my XML file.

<?xml version="1.0" encoding="utf-8" ?>
 <MyFavourates>
  <Favourate Name="Web Sites">
     <Sites Name = "www.c-sharpcorner.com" />
      <Sites Name = "www.vbdotnetheaven.com" />
     <Sites Name = "www.longhorncorner.com" />
     <Sites Name = "www.modelingcorner.com" />
   </Favourate>
   <Favourate Name="Movies">
     <Movie Name = "Once Upon a Time In Maxico" />
     <Movie Name = "Perl Harbour" />
    <Movie Name = "Gladiator" />
    <Movie Name = "Walking Tall" />
  </Favourate>
  <Favourate Name="Technologies">
    <Technology Name = ".NET" />
     <Technology Name = "C#" />
     <Technology Name = "VB.NET" />
     <Technology Name = "ASP.NET" />
     <Technology Name = "WPF" />
     <Technology Name = "WCF" />
   </Favourate>
 </MyFavourates>
  
Now confgure data source.

 
Figure4.

Use Browse button to get XML file from your application.
 

Figure5.

Now put XmlDataSource Id to TreeView DataSourceID.
 

Figure6.

<form id="form1" runat="server">
     <div>    
        <asp:XmlDataSource ID="XmlDataSource1" runat="server" 
             DataFile="~/XML1.xml"></asp:XmlDataSource>     
             <asp:TreeView ID="TreeView1" runat="server" 
             DataSourceID="XmlDataSource1" ImageSet="Contacts" NodeIndent="10">
                <ParentNodeStyle Font-Bold="True" ForeColor="#5555DD" />
                <SelectedNodeStyle 
                Font-Underline="True" HorizontalPadding="0px"
                VerticalPadding="0px" />
                <DataBindings>
                    <asp:TreeNodeBinding DataMember="Favourate" TextField="Name" />
                    <asp:TreeNodeBinding DataMember="Sites" TextField="Name" />
                    <asp:TreeNodeBinding DataMember="Movie" TextField="Name" />
                    <asp:TreeNodeBinding DataMember="Technology" TextField="Name" />
                </DataBindings>
                <NodeStyle Font-Names="Verdana" Font-Size="8pt" 
                ForeColor="Black" HorizontalPadding="5px"
                     NodeSpacing="0px" VerticalPadding="0px" />
                <HoverNodeStyle Font-Underline="False" /> 
            </asp:TreeView>
     </div>
    </form>

Output looks like this.

 
Figure7.
 

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Author
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
DevExpress Free UI Controls
Become a Sponsor
 Comments
Invisible Data? by Rob On October 15, 2008
After follower both your instructions and similar ones for an example in ASP.Net 3.5 for Dummies, I have not gotten anything to appear at runtime. Is there something wrong with the syntax? or a setting that may need changed with my VB? Please give me any advice or direction that may be helpful.
Reply | Email | Modify 
Re: Invisible Data? by Raj On October 16, 2008
There is nothing wrong with syntax, depends how u using. send ur code??
Reply | Email | Modify 
NM by Rob On October 16, 2008
Reply | Email | Modify 
NM by Rob On October 16, 2008
Thanks for the quick response. Came back to it this morning and your example is showing up in the browser. Do you have any advice on how to click on a movie or technology and bring up another page in my website?
Reply | Email | Modify 
NM by Rob On October 16, 2008
Thanks for the quick response. Came back to it this morning and your example is showing up in the browser. Do you have any advice on how to click on a movie or technology and bring up another page in my website?
Reply | Email | Modify 
Few Queries about XML by Rajat On February 18, 2010
What code does XPath Contain?
What is a Transform File? What code does it contain?
Reply | Email | Modify 
Nice by Swathi On July 12, 2011
Very useful and nice article..It helped me...
Reply | Email | Modify 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.