快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

澳门24小时娱乐在线打造:NickLee的学习demo(父子列表清单)



前面我有给NickLee的一个控件地址,不过在线进修没有demo我们很多时刻很难下手,我做了个简单的demo,是关于父子列表清单,我们在很多时刻做erp会碰见bom清单,也便是一个订单对应哪些产品,而一种产品对应哪些零部件,也便是一个产品它会有哪些材料清单。这样就会呈现一个层层展开的关系,而且在设计权限的时刻我们也会碰见父子权限或者高低级权限清单,在曩昔有用过gridview嵌套,后来找到这个控件之后就没有应用了,可以直接实现,不知道大年夜家有没有更好的类似的控件,盼望能够先容。

cs代码:

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using NickLee.Web.UI;

using System.Collections.Generic;

using System.Reflection;

namespace NPOI

{

public partial class _Default : System.Web.UI.Page

{

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

Grid1.NeedRebind += new Grid.NeedRebindEventHandler(OnNeedRebind);

Grid1.NeedDataSource += new Grid.NeedDataSourceEventHandler(OnNeedDataSource);

//加载子列表清单事故

Grid1.NeedChildDataSource += new Grid.NeedChildDataSourceEventHand澳门24小时娱乐在线打造ler(OnNeedChildData);

Grid1.PageIndexChanged += new Grid.PageIndexChangedEventHandler(OnPageChanged);

Grid1.SortCommand += new Grid.SortCommandEventHandler(OnSort);

}

//override protected void OnInit(EventArgs e)

//{

////

//// CODEGEN: This call is required by the ASP.NET Web Form Designer.

////

//InitializeComponent();

//base.OnInit(e);

//}

/////

///// Required method for Designer support - do not modify

///// the contents of this method with the code editor.

/////

//private void InitializeComponent()

//{

////this.Load += new System.EventHandler(this.Page_Load);

//}

#endregion

public static ListModel> ListTable=null;

protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

IListModel> model = new ListModel>{

new Model{ParentId="001000",ChildId="001000",UserName="Bill",Department="IT",IsWork=1},

new Model{ParentId="001000",ChildId="001001",UserName="Bil2",Department="IT",IsWork=1},

new Model{ParentId="001000",ChildId="001002",UserName="Bil3",Department="IT",IsWork=1},

new Model{ParentId="001002",ChildId="001007",UserName="Bil4",Department="IT",IsWork=1},

new Model{ParentId="002000",ChildId="002000",UserName="Bil5",Department="PUR",IsWork=1},

new Model{ParentId="002000",ChildId="002001",UserName="Bil6",Department="PUR",IsWork=1},

new Model{ParentId="002001",ChildId="002002",UserName="Bil7",Department="PUR",IsWork=0},

new Model{ParentId="002002",ChildId="002003",UserName="Bil8",Department="PUR",IsWork=1},

new Model{ParentId="002002",ChildId="002004",UserName="Bil9",Department="PUR",IsWork=1},

new Model{ParentId="002002",ChildId="002005",UserName="Bila",Department="澳门24小时娱乐在线打造PUR",IsWork=1},

new Model{ParentId="003000",ChildId="003000",UserName="Bilc",Department="PE",IsWork=1},

new Model{ParentId="004000",ChildId="004000",UserName="Bilb",Department="ME",IsWork=1},

new Model{ParentId="004000",ChildId="004001",UserName="Bild",Department="ME",IsWork=0},

new Model{ParentId="004000",ChildId="004002",UserNam澳门24小时娱乐在线打造e="Bile",Department="ME",IsWork=1},

new澳门24小时娱乐在线打造 Model{ParentId="004000",ChildId="004003",UserName="Bilf",Department="ME",IsWork=1}

};

ListTable = model as ListModel>;

buildTopLevel();

Grid1.DataBind();

}

}

private void buildTopLevel()

{

var GetDate = from row in ListTable

where row.ParentId == row.ChildId

select new { row.ChildId, row.UserName, row.Department, row.IsWork };

DataTable table = new DataTable("Employee");

table=ListToDataTable(GetDate);

Grid1.DataSource = table;

}

public void OnNeedRebind(object sender, EventArgs oArgs)

{

Grid1.DataBind();

}

public void OnNeedDataSource(object sender, EventArgs oArgs)

{

buildTopLevel();

}

//得到子列表

public void OnNeedChildData(object sender, NickLee.Web.UI.GridNeedChildDataSourceEventArgs args)

{

var GetChildData = from row in ListTable

where row.ParentId == args.Item["ChildId"].ToString() && row.ChildId != args.Item["ChildId"].ToString()

select new { row.ChildId, row.UserName, row.Department, row.IsWork };

DataTable oTable=new DataTable("Employee");

oTable = ListToDataTable(GetChildData);

args.DataSource = oTable;

}

public void OnPageChanged(object sender, NickLee.Web.UI.GridPageIndexChangedEventArgs oArgs)

{

Grid1.C澳门24小时娱乐在线打造urrentPageIndex = oArgs.NewIndex;

}

public void OnSort(object sender, NickLee.Web.UI.GridSortCommandEventArgs oArgs)

{

Grid1.Sort = oArgs.SortExpression;

}

public static DataTable ListToDataTableT>(IEnumerableT> data)

{

PropertyInfo[] ps = typeof(T).GetProperties();

DataTable table = new DataTable();

foreach (PropertyInfo p in ps)

{

table.Columns.Add(p.Name, p.PropertyType);

}

foreach (T t in data)

{

DataRow row = table.NewRow();

foreach (PropertyInfo p in ps)

{

row[p.Name] = p.GetValue(t, null);

}

table.Rows.Add(row);

}

return table;

}

}

public class Model

{

public string ParentId { get; set; }

public string ChildId { get; set; }

public string UserName { get; set; }

public string Department { get; set; }

public int IsWork { get; set; }

}

}

您可能还会对下面的文章感兴趣: