---
title: "Populate Grid Control From XML Document Easily"  
description: "In this tutorial, I am going to teach you,how to populate the data grid control from Your XML Document as data source.  Default.aspx  PageLanguage=\"C#"  
author: "mohan kumar"  
published: 2011-11-29  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/830/populate-grid-control-from-xml-document-easily  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 1 minute  

---

# Populate Grid Control From XML Document Easily

In this [tutorial](https://yourviews.mindstick.com/view/81591/semrush-tutorial-and-review-2020-how-to-use-it-to-20x-your-website-traffic), I am going to [teach](https://yourviews.mindstick.com/story/3814/10-things-must-teach-to-indian-youths) you,how to [populate](https://www.mindstick.com/blog/60/populate-records-in-second-listbox-according-to-the-selection-in-first-list-box) the [data grid](https://www.mindstick.com/forum/105/what-events-fire-when-binding-data-to-a-data-grid) [control](https://yourviews.mindstick.com/view/83439/bipartisan-gun-control-bill-passed-in-us-after-decades) from Your XML [Document](https://www.mindstick.com/articles/328642/what-to-consider-while-choosing-a-software-documentation-tool) as [data source](https://www.mindstick.com/forum/160659/how-do-you-create-a-custom-filter-to-filter-any-text-in-the-data-source-in-angularjs).\

##### Default.aspx

##### ```
 <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title>Untitled Page</title></head><body>    <form id="form1" runat="server">    <div>        <asp:GridView ID="dgBooks" runat="server" CellPadding="4" ForeColor="#333333"            GridLines="None">            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />  
         <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />            <EditRowStyle BackColor="#999999" />            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />        </asp:GridView>    </div>    </form></body></html>
```

##### Default.aspx.cs

```
using System;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page{      protected void Page_Load(object sender, EventArgs e)    {        if (!Page.IsPostBack)        {            loadMyGridFromXML();        }    }     public void loadMyGridFromXML()    {       DataSet myDataSet = new DataSet();       myDataSet.ReadXml(Server.MapPath("books.xml"));       dgBooks.DataSource
= myDataSet;       dgBooks.DataBind();    }} 
```

Before adding the above [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii), create an XML Page and add the following code and save it.

##### Books.xml

```
<?xml version="1.0"encoding="utf-8" ?><books>  <book>    <title>Teach Yourself Active Server Pages 3.0 in 21 Days</title>    <author>Mitchell</author>    <year>1999</year>  </book>  <book>    <title>Designing Active Server Pages</title>    <author>Mitchell</author>    <year>2000</year>  </book>  <book>    <title>ASP.NET: Tips, Tutorials, and Code</title>    <author>Mitchell</author>    <year>2001</year>  </book>  <book>    <title>ASP Unleashed</title>    <author>Walther</author>    <year>1998</year>  </book>  <book>    <title>ASP.NET Unleashed</title>    <author>Walther</author>    <year>2002</year>  </book>  <book>    <title>Creating Data Driven ASP.NET Applications</title>    <author>Seven</author>    <year>2002</year>  </book></books>
```

##### And Your Output Looks like:-

![Populate Grid Control From XML Document Easily](https://www.mindstick.com/mindstickarticle/6c3ccf8c-6656-4a48-bfb7-e0221569de67/images/1a5257f0-9385-41df-8898-790ff62f9c6b.png)

Happy Coding. Keep on coding as far as possible.

\

---

Original Source: https://www.mindstick.com/articles/830/populate-grid-control-from-xml-document-easily

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
