对“打造基于jQuery的高性能TreeView”的扩展
2009-10-28 00:00:00 来源:WEB开发网为了直观,截个图:
1、 先建立一个静态类,来扩展TreeItem类:
public static class TreeItemHelper
{
}
2、 添加扩展方法:
/**//// <summary>
/// 生成树类
/// </summary>
/// <param name="ti">要装载的树类根节点</param>
/// <param name="drs">数据表</param>
/// <param name="sId">父类ID</param>
/// <returns></returns>
private static TreeItem GetTreeItemFromDataTable(this TreeItem ti, EnumerableRowCollection<DataRow> drs, string sId)
{
ti.ChildNodes = new List<TreeItem>();
var drs0 = drs.Where(p => p.Field<int>("parent").ToString() == sId);
foreach (DataRow dr in drs0)
{
string parent = dr["Id"].ToString();
var ti0 = new TreeItem() { id = int.Parse(parent), value = parent, text = dr["text"].ToString() };
ti0 = ti0.GetTreeItemFromDataTable(drs, parent);
ti.Add(ti0);
}
return ti;
}
更多精彩
赞助商链接