In this tutorial, I am going to teach you,how to populate the data grid control from Your XML Document as data source.

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
        <asp:GridView ID="dgBooks" runat="server" CellPadding="4" ForeColor="#333333"
            <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" />

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)
    public void loadMyGridFromXML()
       DataSet myDataSet = new DataSet();
       dgBooks.DataSource = myDataSet;

Before adding the above code, create an XML Page and add the following code and save it.

<?xml version="1.0"encoding="utf-8" ?>
    <title>Teach Yourself Active Server Pages 3.0 in 21 Days</title>
    <title>Designing Active Server Pages</title>
    <title>ASP.NET: Tips, Tutorials, and Code</title>
    <title>ASP Unleashed</title>
    <title>ASP.NET Unleashed</title>
    <title>Creating Data Driven ASP.NET Applications</title>

And Your Output Looks like:-

Populate Grid Control From XML Document Easily

Happy Coding. Keep on coding as far as possible.

  Modified On Nov-30-2017 12:44:32 AM

Leave Comment