<?xml version="1.0" encoding="utf-8" ?>
<employee>
<empdetails>
<name>santosh</name>
<age>24</age>
<salary>20000</salary>
</empdetails>
<empdetails>
<name>srinu vas</name>
<age>21</age>
<salary>30000</salary>
</empdetails>
<empdetails>
<name>anil</name>
<age>25</age>
<salary>40000</salary>
</empdetails>
</employee>
<%@ 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">
<h2 style=" color:blue; font-style:normal ">
Xml values Show in Gridview
<br /> in asp.net
</h2>
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="name" HeaderText="Emp Name" />
<asp:BoundField DataField="age" HeaderText="Emp Age" />
<asp:BoundField DataField="salary" HeaderText="Emp salary" />
</Columns>
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
</form>
</body>
</html>
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("App_Data/testxml.xml"));
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
}
No comments:
Post a Comment