Load XML file data in Gridview without code Asp.net C# VB.Net

XML is one of the most popular data source. Basically XML files is used for transferring data. If you need to load data from an XML file and to display those data in a tabular format then you can use Gridview control. In this tutorial i will discuss “how you can bind XML file or Load XML file in a Gridview without writing code“. Please follow the below steps:

Bind XML File in Design Mode:
To run this example at first add an XML file in your project and name the file XMLFile.xml. Now modify the XML in the following way:

Add an XML File in your Project:
Right click on project. Select Add new Item. Then select XML File. The by default name is “XMLFile.xml”. SO no need to change the XML file name. The XML file automatically open in the code window. This process is same for both C# and VB.Net.

Now fill up the XML file with some data to test:

<?xml version="1.0" encoding="utf-8" ?>
  <Asp.net Id="0001" Title="Bind Dropdown List" Visit="985" Modified="Jan 01, 2009"></Asp.net>
  <Asp.net Id="0002" Title="Event calendar" Visit="777" Modified="Feb 01, 2009"></Asp.net>
  <Asp.net Id="0003" Title="Select all checkboxes" Visit="853" Modified="Mar 01, 2009"></Asp.net>
  <Asp.net Id="0004" Title="Transfer data between" Visit="957" Modified="Apr 01, 2009"></Asp.net>

Now add a GridView control in your page. The next step is to click on the GridView control’s smart tag and click on the “Choose Data Source” dropdown list. This opens the Data Source Configuration Wizard. Select XML File and click OK. Now locate the file. That’s it. If not yet clear follow the below snapshot:

Now run the project. Hope you will get your desired output page like below:

Note: In Configuration data source wizard you saw that i keep blank Transform file and Xpath expression. You can set the Transform file value by your XSLT and use Xpath expression to bind the selected node from your XML file.

Download Code Example C#        Download Code Example VB.Net

Leave a Reply

Your email address will not be published. Required fields are marked *

AlphaOmega Captcha Classica  –  Enter Security Code