您的位置:首页 > 运维架构

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

2012-12-20 18:38 316 查看
*******************Dome3.aspx

 书名:<asp:DropDownList ID="DropDownList1"

            runat="server" Height="28px" Width="136px">

        </asp:DropDownList>

 <asp:Button ID="Button2" runat="server" Xonclick="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;

                }

          }

        }

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐