Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Tuesday, 21 November 2017

Saturday, 30 January 2016

How to bind GridView control from xml file in with C#

In this article, I will explain you how to bind GridView control from a XML file in with C#.

Creating Data Source

First, we need to create a xml file named as StudentDetails.xml. To create a XML file.
Go to: website >right click >add new item >go to data tab >select xml file >save file named as StudentDetails.xml at root directory.

Below is the xml file containing the Student details.

<?xml version="1.0" encoding="utf-8" ?>

In Designer File

In designer file, create a GridView control named as grdStudent.

 <div align="center">
  <asp:GridView ID="grdStudent" runat="server"> <HeaderStyle BackColor="#00A6DC" ForeColor="White"/>

Namespace Used

Include the below Namespace.

using System.Data;

Complete C# Code

ReadXml() method will read data into a DataSet from specified XML file.

        protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)

        private void BindGrid()
            DataSet ds = new DataSet();
            grdStudent.DataSource = ds.Tables[0];


Output will be shown as below.

Bind GridView from a xml file

Email Subscription

Subscribe to our newsletter to get the latest articles directly into your inbox

Blog Archive

Ads By Chitika