61,655
社区成员




<?xml version="1.0" encoding="utf-8" ?>
<root>
<car Brand="Ford" Name="Fox" GearBox="MT" Displacement="1.6" ></car>
<car Brand="Das Auto" Name="Bora" GearBox="MT" Displacement="1.6" ></car>
<car Brand="Audi" Name="A4L" GearBox="IVS" Displacement="2.0T" ></car>
<car Brand="Nissan" Name="Sunny" GearBox="IVS" Displacement="1.5" ></car>
<car Brand="Buick" Name="Excelle XT" GearBox="AT" Displacement="1.6" ></car>
</root>
<!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 id="Head1" runat="server">
<title></title>
<style>
.divStyle {
float: left;
width: 200px;
height: 200px;
border: 1px solid black;
}
#div3 {
clear: both;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="div1" class="divStyle">
<asp:DropDownList ID="DropDownList1" runat="server" DataTextField="Name" DataValueField="Name" AutoPostBack="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
</div>
<div id="div2" class="divStyle"></div>
<div id="div3" class="divStyle"></div>
<div id="div4" class="divStyle" runat="server"></div>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("~/test.xml"));
DataTable dt1 = ds.Tables[0];
dt1.DefaultView.RowFilter = "Displacement='1.6'";
DataTable dt2 = dt1.DefaultView.ToTable();
DropDownList1.DataSource = dt2;
DropDownList1.DataBind();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("~/test.xml"));
XmlNode car = xmlDoc.SelectSingleNode(@"/root/car[@Name='" + DropDownList1.SelectedValue + "']");
div4.InnerText = string.Format(@"Brand=""{0}"" GearBox=""{1}"" Displacement=""{2}""", car.Attributes["Brand"].Value, car.Attributes["GearBox"].Value, car.Attributes["Displacement"].Value);
}