<1>DropDownList控件----V <asp:DropDownList ID="compactType" runat="server" AutoCallBack="True" Width="153px"> </asp:DropDownList> <2> Xml文件文档 <?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> <3>读取xmlwen见进行绑定的方法---M /// <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(); } <4>调用 SecurityFactory sf = new SecurityFactory(); //xml文件路径 string path2 = Server.MapPath("./xml/XMLFile2.xml"); sf.ReadXml(path2, this.compactType, "id", "val"); 绑定成功!!!
读取Xml文件进行绑定数据
最新推荐文章于 2018-06-13 11:43:43 发布