HTML:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ExWithGrid.aspx.cs" Inherits="ExWithGrid" %>
<%@ Register assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.DataVisualization.Charting" tagprefix="asp" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="true"
AutoGenerateColumns="False" PageSize="2"
PagerSettings-Mode="NextPreviousFirstLast" PagerSettings-FirstPageText="First" PagerSettings-LastPageText="Last" PagerSettings-NextPageText="Next" PagerSettings-PreviousPageText="Previous"
onpageindexchanging="GridView1_PageIndexChanging">
<Columns>
<asp:BoundField HeaderText="BookID" DataField="id" ReadOnly="True"/>
<asp:BoundField HeaderText="Author" DataField="author" ReadOnly="true"/>
<asp:BoundField HeaderText="Title" DataField="title" ReadOnly="True"/>
<asp:BoundField HeaderText="Genre" DataField="genre" ReadOnly="True"/>
<asp:BoundField HeaderText="Price" DataField="price" ReadOnly="True"/>
<asp:BoundField HeaderText="Publish_date" DataField="publish_date" DataFormatString="{0:yyyy-MM-dd}" HtmlEncode="false" ApplyFormatInEditMode="true" />
<asp:BoundField HeaderText="Description" DataField="description" ReadOnly="True"/>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Code Behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Data;
public partial class ExWithGrid : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
getdata();
}
}
private void getdata()
{
DataSet ds = new DataSet();
ds.ReadXml(@"C:\Documents and Settings\rajshree\Desktop\Library.xml");
GridView1.DataSource = ds;
GridView1.DataBind();
}
}