*******************Dome3.aspx
书名:<asp:DropDownList ID="DropDownList1"
runat="server" Height="28px" Width="136px">
</asp:DropDownList>
<asp:Button ID="Button2" runat="server" Xοnclick="Button1_Click" Text="查看详情" />
<table style="width:50%;">
<tr>
<td class="style1">
作者:</td>
<td>
<asp:TextBox ID="txtauthor" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
出版社:</td>
<td>
<asp:TextBox ID="txtpublisher" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
出版年:</td>
<td>
<asp:TextBox ID="txtencoding" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
Isdn号:</td>
<td>
<asp:TextBox ID="txtid" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
价格:</td>
<td>
<asp:TextBox ID="txtprice" runat="server"></asp:TextBox>
</td>
</tr>
</table>
*******************Dome3.aspx.cs
public partial class Dome3 : System.Web.UI.Page
{
XmlDocument xdoc;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
xdoc = new XmlDocument();
xdoc.Load(Server.MapPath("books.xml"));
XmlNodeList list = xdoc.GetElementsByTagName("name");
foreach (XmlNode node in list)
{
this.DropDownList1.Items.Add(node.InnerText);
}
Session["doc"] = xdoc;
}
else
{
xdoc = Session["doc"] as XmlDocument;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
XmlNode node = xdoc.DocumentElement.SelectSingleNode("book[name='" + DropDownList1.Text + "']");
foreach (XmlNode item in node.ChildNodes)
{
if (item.LocalName == "author")
{
this.txtauthor.Text = item.InnerText;
}
if (item.LocalName == "publisher")
{
this.txtpublisher.Text = item.InnerText;
}
if (item.LocalName == "date")
{
this.txtencoding.Text = item.InnerText;
}
if (item.LocalName == "isbn")
{
this.txtid.Text = item.InnerText;
}
if (item.LocalName == "price")
{
this.txtprice.Text = item.InnerText;
}
}
}
}