Friday, November 25, 2011

XML data into Gridview in

Title:how to bind XML data in grid view in using

We have seen different examples on  how to bind data to Grid view in ,Import XML data to Grid View,bind data table to Grid view.Now i would like show how to bind the XML data to grid view.Before going to start  you may think we have to use XML classes to read the data,But we will not use any XML classes .In Data set has property to read the XML data which is Readxml().
XML Data:
<?xml version="1.0" encoding="utf-8" ?>

Aspx Page:

<html xmlns="">
<head id="Head1" runat="server">
<title>Bind XML data to Gridview in</title>
<form id="form1" runat="server">
<asp:GridView ID="GVdynamicXML" runat="server" AutoGenerateColumns="False"
<asp:BoundField DataField="OrderID" HeaderText="OrderID"
 SortExpression="OrderID" />
<asp:BoundField DataField="OrderName" HeaderText="OrderName"
 SortExpression="OrderName" />
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
<asp:BoundField DataField="Amount" HeaderText="Amount"
SortExpression="Amount" />

Code behind:
using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class _XMLbindGridviewDefault3 : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
DataSet myDataSet = new DataSet();
GVdynamicXML.DataSource = myDataSet;
We should give a specific path of XML file to read the data using Readxml().Then bind the data  to grid view "gd_view"
Post a Comment