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");
相关文档:
用c#给PDA做了一个PC端的通讯程序,需要保存两个参数。用Delphi时,是保存在ini文件中,c#读写XML比较方便,就用xml文件来保存了。
class CXmlClass
{
private string XmlFilePath;
/// <summary>
/// 下载到PDA的TXT文件路径
/// </summary>
......
<asp:TemplateField HeaderText="测试">
<ItemTemplate>
<asp:LinkButton ID="test" runat="server" OnClick="test_Click" OnClientClick='<%# string.Format("return confirmDelete(\"{0} {1}\");", DoEscape((string)Eval( ......
方法一:
HtmlProxy.cs:
using System.Text;
using System.IO;
/// <summary>
/// HtmlProxy 的摘要说明
/// </summary>
public class HtmlProxy
{
public HtmlProxy()
{
//
......
上次我们说到的编译成的dll文件与cs文件在同一目录中,而不会放到虚拟目录的bin目录中,如何做才能够把cs
文件编译成dll且自动放到虚拟目录的bin文件夹中呢?
开始-------程序-------Microsoft Visual Studio.NET 2003-------Visual Studio.NET工具,点击其中的“Visual Studio.NET2003命令提示”,就会进入Mic ......
一、(单值绑定)在页面的后台代码中定义公有变量,如下:
public string gongYou = "声明的公有成员";
①然后在页面的源中调用,如下:
<asp:Label ID="lblMgs" runat="server" Text="<%#gongYou >"></asp:Label>
②当然最后要记得绑定数据:
protected void Page_Load(object ......