您的位置:首页 > 数据库

利用数据库来填充UltraWebTree

2007-09-10 13:19 344 查看

刚做过资源库小程序,用到了UltraWebTree ,利用数据库中的数据填充了树,以下是心得。


填充思想:先从表中找到根节点数据,生成节点插入到UltraWebTree中,然后利用递归寻找当前节点的子节点,生成节点,插入。


注意,需要using Infragistics.WebUI.Shared 空间


资源库表结构(两个表category与files):


category(存放资源文件目录列表)


cid cname cfatherid


cid是标示,cname目录名称,cfatherid父目录名称


files(存放fcid对应目录下的文件名称)


fid fname fcid




代码:


Page_Load中






if (!Page.IsPostBack)




...{


DataTable data= Query.ProcessSql("SELECT cid,cfatherid,cname FROM category",GlobalVar.DBName);


this.InitTree(this.UltraWebTree1.Nodes, "0",data);


}




GlobalVar.DBName ->数据库名。


Query.ProcessSql ->我用了听棠的SPL持久层来做的。


对应的InitTree如下:






private void InitTree(Infragistics.WebUI.UltraWebNavigator.Nodes Nds,string cfatherid,DataTable data)




...{


Infragistics.WebUI.UltraWebNavigator.Node tmpNd;


DataRow [] rows = data.Select("cfatherid='" + cfatherid + "'");


foreach(DataRow row in rows)




...{


tmpNd = new Infragistics.WebUI.UltraWebNavigator.Node();


tmpNd.DataKey = int.Parse(row["cid"].ToString());


tmpNd.Text = row["cname"].ToString();


Nds.Add(tmpNd);


InitTree(tmpNd.Nodes, tmpNd.DataKey.ToString(),data);


}


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: