c#读取xml内容保定到dropdownlist
来源:互联网 发布:言论自由与网络暴力 编辑:程序博客网 时间:2024/04/28 01:54
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="xmldemo2.aspx.cs" Inherits="Ado_upper.xmldemo2" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr><td colspan=2>书名<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="显示详细信息" onclick="Button1_Click" /></td></tr>
<tr><td>作者</td> <td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td></tr>
<tr><td>作者</td> <td><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td></tr>
<tr><td>作者</td> <td><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td></tr>
<tr><td>作者</td> <td><asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></td></tr>
<tr><td>作者</td> <td><asp:TextBox ID="TextBox5" runat="server"></asp:TextBox></td></tr>
<tr><td>作者</td> <td><asp:TextBox ID="TextBox6" runat="server"></asp:TextBox></td></tr>
</table>
</div>
</form>
</body>
</html>
apx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
namespace Ado_upper
{
public partial class xmldemo2 : System.Web.UI.Page
{
XmlDocument xdoc;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load(Server.MapPath("books.xml"));//声明一个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.TextBox1.Text = item.InnerText;
}
if (item.LocalName == "publisher")
{
this.TextBox2.Text = item.InnerText;
}
if (item.LocalName == "date")
{
this.TextBox3.Text = item.InnerText;
}
if (item.LocalName == "name")
{
this.TextBox4.Text = item.InnerText;
}
if (item.LocalName == "isbn")
{
this.TextBox5.Text = item.InnerText;
}
if (item.LocalName == "price")
{
this.TextBox6.Text = item.InnerText;
}
}
}
}
}
内容上划红圈的地方请忽略。代码改一下就可以了。
- c#读取xml内容保定到dropdownlist
- C#读取XML内容
- XML文件读取数据绑定到DropDownList
- 从XML文件中读取数据绑定到DropDownList
- 从XML文件中读取数据绑定到DropDownList
- 如何从XML文件中读取数据绑定到DropDownList
- 从XML文件中读取数据绑定到DropDownList
- 从XML文件中读取数据绑定到DropDownList
- 从XML文件中读取数据绑定到DropDownList
- 使用XmlDocument 读取books.xml中的书名到DropDownList中
- 使用XmlDocument 读取books.xml中的书名到DropDownList中
- C# 读取 XML 到TreeView
- 读取xml文件中的内容到HashTable
- 读取xml文件内容到数据库
- c#读取xml文件的节点内容
- C#之读取XML文件内容
- C#读取XML文件的内容
- C#读取csv文件内容到DataTable
- oracle常用函数操作记录
- md5到md5破解的一些科普
- 右手握左手
- 统计学习笔记(1)——统计学习方法概论
- 通过jobtracker、tasktraker的log分析mapreduce的过程
- c#读取xml内容保定到dropdownlist
- 学习linux的感想
- VC+SQLite 使用笔记
- apache2.2 虚拟主机配置
- eclipse android程序第三方jar加如source和doc
- linux IIC 驱动
- QQ客服代码
- 一种基于矩形块的颜色渲染方式实现二维数据可视化
- linux命令(1)