How to Bind XML file to Gridview in | ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

How to Bind XML file to Gridview in

Introduction: In this post I will explain how we can bind the XML file to Gridview in
I have created a XML file named Student_Detail.xml and have data below mention:
<?xml version="1.0" encoding="utf-8" ?>

Now add a new webform to project. Drag and drop the
Gridview Data control from Toolbox>Data control.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
                <asp:TemplateField HeaderText="STUDENT NAME">
                        <asp:Label ID="lblname" runat="server" Text='<%# Eval("NAME") %>'></asp:Label>
                <asp:TemplateField HeaderText="STUDENT ADDRESS">
                        <asp:Label ID="lbladdress" runat="server" Text='<%# Eval("ADDRESS") %>'></asp:Label>
                <asp:TemplateField HeaderText="MARKS OBTAINED">
                        <asp:Label ID="lblclass" runat="server" Text='<%# Eval("Marks") %>'></asp:Label>

Now to go .aspx.cs page and add namespace.
using System.Xml;
using System.Data;

protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
    private void Bindxml()
        DataSet dt = new DataSet();
        if (dt.Tables[0].Rows.Count > 0)
            GridView1.DataSource = dt;
            Response.Write("No Record Found");


Imports System.Data
Imports System.Xml

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
        End If
    End Sub
    Private Sub Bindxml()
        Dim dt As New DataSet()
        If dt.Tables(0).Rows.Count > 0 Then
            GridView1.DataSource = dt
            Response.Write("No Record Found")
        End If
    End Sub

Run the project and Check the result.

Related Articles on Gridview:
Ø  How to use RadioButtonList control inside the Gridview                         
Ø  How to Bind Gridview with Datareader in

Is it helpful?

If yes post your comment to admire my work. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.

Post a Comment



Contact Form


Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget