zoukankan      html  css  js  c++  java
  • 如何使用Insus.NET的List Control Utility类库

    刚帖完这个类库http://www.cnblogs.com/insus/archive/2013/01/28/2880618.html,就有网友在SKYPE问及,怎样使用它?

    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);
        }   
    }


    运行效果:

  • 相关阅读:
    Luogu P1020 导弹拦截
    洛谷 p1196 带权并查集
    gradle 语法基础
    Codeforces Round #542 div.2 C
    我了解的字符编码
    洛谷p3374 树状数组1
    树状数组2
    线段树模板 求区间和, 区间加法,乘法更新
    洛谷 p1886 滑动窗口
    HDOJ.1251
  • 原文地址:https://www.cnblogs.com/insus/p/2880656.html
Copyright © 2011-2022 走看看