asp.net 读取Xml文件并进行DropDownList数据绑定
<asp:DropDownList ID="compactType" runat="server" AutoCallBack="True" Width="153px"> </asp:DropDownList>
<?xml version="1.0" encoding="utf-8" ?>
<roots>
<root>
<id>1</id>
<Culture>初中以下</Culture>
</root>
<root>
<id>2</id>
<Culture>初中</Culture>
</root>
<root>
<id>3</id>
<Culture>中专</Culture>
</root>
<root>
<id>4</id>
<Culture>高中</Culture>
</root>
<root>
<id>5</id>
<Culture>大专</Culture>
</root>
<root>
<id>6</id>
<Culture>本科</Culture>
</root>
</roots>
/// <summary>
/// 读取xml文件,用数据填充DropDownList,进行绑定
/// </summary>
/// <param name="path">xml文件路径</param>
/// <param name="dp">要进行绑定的DropDownList名称</param>
/// <param name="id">DropDownList要显示的文本(xml文件的一个节点)</param>
/// <param name="val">DropDownList要显示的值(xml文件的一个节点)</param>
public void ReadXml(string path,DropDownList dp,string id,string val)
{
DataSet ds = new DataSet();
ds.ReadXml(path);
dp.DataSource = ds;
dp.DataTextField = id ;
dp.DataValueField = val;
dp.DataBind();
}
SecurityFactory sf = new SecurityFactory();
//xml文件路径
string path2 = Server.MapPath("./xml/XMLFile2.xml");
sf.ReadXml(path2, this.compactType, "id", "val");
相关文档:
XML在我们的程序中用到的越来越多,因为它存储、读取、修改都比较方便。
下面我来分享一下XML的常用操作(增删改查),下面是程序运行效果:
增(增加节点包括创建XML):
/// <summary>
/// 创建XML文档
/// </summary>
/// <param name="path"></param>
......
一、简单介绍
using System.Xml;
//初始化一个xml实例
XmlDocument xml=new XmlDocument();
//导入指定xml文件
xml.Load(path);
xml.Load(HttpContext.Current.Server.MapPath("~/file/bookstore.xml"));
//指定一个节点
XmlNode root=xml.SelectSingleNode("/root");
//获取节点下所有直接子节点
XmlNodeList ch ......
1.route.xml文件内容
<?xml version="1.0" encoding="GBK"?>
<root>
<route id="1111">
<id>111</id>
<name>四川</name>
<path>www.baidu.com/hehe.html</path>
</route>
</root>
2.test.html代码
<html>
<body>
<script> ......
对“添加”、“提交”、“保存”、“更新”等按钮需要对数据库进行写操作的按钮,一定要在页面初始化时加载脚本,防止多次重复点击,例如:
protected void Page_Load(object sender, EventArgs e)
{
//.net 2.0以上
......
1 使用标准HTML来进行图片上传
前台代码:
<body>
<form id="form1" runat="server">
<div>
<table>
&nbs ......