页面文件:Default2.asp
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 Default2 : System.Web.UI.Page

...{
protected void Page_Load(object sender, EventArgs e)

...{
if (!Page.IsPostBack)

...{
ShowName();
}
}

private void ShowName()

...{
DataSet myxml = new DataSet();
myxml.ReadXml(HttpContext.Current.Server.MapPath("Section.xml"));
ListBox1.DataSource = myxml;
ListBox1.DataTextField = "Name";
ListBox1.DataValueField = "Name";
ListBox1.DataBind();
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)

...{
if (ListBox1.SelectedIndex > -1)

...{
XmlDocument myxmldoc = new XmlDocument();
myxmldoc.Load(HttpContext.Current.Server.MapPath("Section.xml"));
String xpath = "/SectionList/Section[@Name = '"+ListBox1.SelectedValue.ToString()+"']";
XmlNodeList mynode = myxmldoc.SelectNodes(xpath);
foreach (XmlNode ne in mynode)

...{
TextBox1.Text = ne["EMSName"].InnerText.ToString();
TextBox2.Text = ne["SectionState"].InnerText.ToString();
TextBox3.Text = ne["NEA"].InnerText.ToString();
TextBox4.Text = ne["NEPortA"].InnerText.ToString();
TextBox5.Text = ne["NEZ"].InnerText.ToString();
TextBox6.Text = ne["NEPortZ"].InnerText.ToString();
TextBox7.Text = ne["LayerSpeed"].InnerText.ToString();
TextBox8.Text = ne["Direct"].InnerText.ToString();
TextBox9.Text = ne["RunState"].InnerText.ToString();
TextBox10.Text = ne["Info"].InnerText.ToString();
}
}
else

...{
Response.Write("<script>alert("你还没有选择内容!");</script>");
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<SectionList>
<Section Name="沈调新楼~沈调老楼.段1/2.5G">
<EMSName>NULL</EMSName>
<SectionState>开通</SectionState>
<NEA>NEC.Unode(BBM).传输设备1/2.5G</NEA>
<NEPortA>端口1/2.5G/光口</NEPortA>
<NEZ>NEC.Unode(BBM).传输设备2/2.5G</NEZ>
<NEPortZ>端口1/2.5G/光口</NEPortZ>
<LayerSpeed>2.5G</LayerSpeed>
<Direct>双向</Direct>
<RunState>工作</RunState>
<Info>NULL</Info>
</Section>
<Section Name="沈调老楼~辽局调.段1/2.5G">
<EMSName>NULL</EMSName>
<SectionState>开通</SectionState>
<NEA>NEC.Unode(BBM).传输设备2/2.5G</NEA>
<NEPortA>端口2/2.5G/光口</NEPortA>
<NEZ>华为.Optix.传输设备1/2.5G</NEZ>
<NEPortZ>端口1/2.5G/光口</NEPortZ>
<LayerSpeed>2.5G</LayerSpeed>
<Direct>双向</Direct>
<RunState>工作</RunState>
<Info>NULL</Info>
</Section>
<Section Name="辽局调~铁局调.段1/2.5G">
<EMSName>NULL</EMSName>
<SectionState>开通</SectionState>
<NEA>华为.Optix.传输设备1/2.5G</NEA>
<NEPortA>端口2/2.5G/光口</NEPortA>
<NEZ>中兴.传输设备1/2.5G</NEZ>
<NEPortZ>端口1/2.5G/光口</NEPortZ>
<LayerSpeed>2.5G</LayerSpeed>
<Direct>双向</Direct>
<RunState>工作</RunState>
<Info>NULL</Info>
</Section>
<Section Name="铁局调~沈调新楼.段1/2.5G">
<EMSName>NULL</EMSName>
<SectionState>开通</SectionState>
<NEA>中兴.传输设备1/2.5G</NEA>
<NEPortA>端口2/2.5G/光口</NEPortA>
<NEZ>NEC.Unode(BBM).传输设备1/2.5G</NEZ>
<NEPortZ>端口2/2.5G/光口</NEPortZ>
<LayerSpeed>2.5G</LayerSpeed>
<Direct>双向</Direct>
<RunState>工作</RunState>
<Info>NULL</Info>
</Section>
</SectionList>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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>使用XML示例</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ListBox ID="ListBox1" runat="server" Height="97px" Width="184px" AutoPostBack="True" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged"></asp:ListBox><br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox7" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox8" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox9" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox10" runat="server"></asp:TextBox>
</form>
</body>
</html>
<!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>使用XML示例</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ListBox ID="ListBox1" runat="server" Height="97px" Width="184px" AutoPostBack="True" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged"></asp:ListBox><br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox7" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox8" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox9" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox10" runat="server"></asp:TextBox>
</form>
</body>
</html>
页面上一个ListBox,十个TextBox,实现页面载入显示xml节点Section名称,点任一名称,显示对应的内容.
处理代码:Default2.aspx.cs



































































XML文档:Section.xml


















































