使用XmlDocument将dropdownlist中显示的书名的其它信息读入到相应的文本框中。

*******************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;
                }

          }
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值