<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="ConditionalBinding.aspx.cs"
Inherits="ConditionalBinding" %>
<!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">
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
public partial class ConditionalBinding : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("Class.xml"));
XmlNodeList lst = doc.SelectNodes("//student[class='class2']");
IList datasource = new ArrayList();
foreach (XmlNode stu in lst)
{
Stu s = new Stu();
s.Name = stu.SelectSingleNode("name").InnerText;
s.Stuclass = stu.SelectSingleNode("class").InnerText;
datasource.Add(s);
}
this.GridView1.DataSource = datasource;
GridView1.DataBind();
}
public class Stu
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private string stuclass;
public string Stuclass
{
get { return stuclass; }
set { stuclass = value; }
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<root>
<student>
<class>class1</class>
<name>ss</name>
</student>
<student>
<class>class1</class>
<name>ss</name>
</student>
<student>
<class>class1</class>
<name>ss</name>
</student>
<student>
<class>class1</class>
<name>ss</name>
</student>
<student>
<class>class2</class>
<name>ss</name>
</student>
</root>