Ok,Insus.NET举一个小例子,实现DropDownList控件,并添加一个空选择(请选择...)之类。准备好数据,Insus.NET在站点的App_Data目录之下,添加一个XML文件:
Whether.xml
<?xml version="1.0" encoding="utf-8" ?><Whethers> <Whether> <WhetherId>0</WhetherId> <WhetherName>否</WhetherName> </Whether> <Whether> <WhetherId>1</WhetherId> <WhetherName>是</WhetherName> </Whether></Whethers>
写一个方法,读取XML文件,并转为DataTable:
View Code
private DataTable DataSource(string xmlFile) { DataSet objDs = new DataSet(); objDs.ReadXml(HttpContext.Current.Server.MapPath("~/App_Data/" + xmlFile)); return objDs.Tables[0]; }
在.aspx网页拉一个DropDownList控件:
View Code
<asp:DropDownList ID="DropDownListBooleanDemo" runat="server"></asp:DropDownList>
接下来,就是怎样使用Insus.NET的类库,是绑定这个DropDownList控件:
上图可编辑代码:
View Code
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using Insus.NET;public partial class Default2 : System.Web.UI.Page{ InsusListControlUtility obj = new InsusListControlUtility(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Data_Binding(); } } private void Data_Binding() { DataTable dt = DataSource("Whether.xml"); obj.DropDownListParse(this.DropDownListBooleanDemo, dt, "WhetherName", "WhetherId", string.Empty); } }
运行效果: