使用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;
}
}
}
}
书名:<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;
}
}
}
}
相关文章推荐
- 5使用XmlDocument将dropdownlist中显示的书名的其它信息读入到相应的文本框中。
- 使用XmlDocument将dropdownlist中显示的书名的其它信息读入到相应的文本框中
- 使用XmlDocument将dropdownlist中显示的书名的其它信息读入到相应的文本框中
- 使用XmlDocument将dropdownlist中显示的书名的其它信息读入到相应的文本框中
- 使用XmlDocument将dropdownlist中显示的书名的其它信息读入到相应的文本框中。添加 :删除按钮,修改并保存按钮 和 添加按钮。完成这些按钮所对应的功能(XmlDocument)
- 使用XmlDocument 读取books.xml中的书名到DropDownList中。(4-2选作使用XmlReader读取books.xml中的书名到DropDownList中)
- 使用cookie技术实现,缓存最近浏览过详细信息的三本书的书名列表,并进行相应显示
- 使用XmlDocument 读取books.xml中的书名到DropDownList中
- 使用XmlDocument 读取books.xml中的书名到DropDownList中
- 使用XmlDocument 读取books.xml中的书名到DropDownList中
- 新建页面DataXML,使用GridView显示book.xm中的图书信息(将books.xml文档和dataSet交互。 )
- SQL Server 2008 R2——使用FOR XML PATH实现多条信息按指定格式在一行显示
- 新建页面DataXML,使用GridView显示book.xm中的图书信息(将books.xml文档和dataSet交互。注意:DataView的使用。ds.Tables[0].defaultView
- 关于awk与其它命令一起使用显示文本信息
- 使用XMLConfiguration解析xml,properties等相应信息
- 显示文本框中的输入信息
- Android 各控件的使用 - 显示文本框(TextView)
- 使用 XSLT 显示 XML
- 为自定View添加相应属性,在XML可以直接使用
- 使用Document Viewer查看pdf文档显示方块乱码: