数据库表结构为:
表名:treeTable 字段:L_ID:主键ID L_Name:树中显示的菜单名 P_L_ID:属于某个菜单 L_Page:导向路径 L_PageName:文件名
示例数据:
L_ID
L_Name
P_L_ID
L_Page
L_PageName
1
根1
0
.....
......
2
根2
0
......
.......
3
子11
1
.....
......
4
子12
1
......
.......
5
子13
1
......
......
6
子21
2
.......
......
//
数据绑定左边web菜单
private
void
DataBindWebList()
...
{ DataConn dc = new DataConn(SpecialClass.strConn); DataTable dt = new DataTable (); dt = dc.GetDataTable( " select L_ID,L_Name,P_L_ID,(L_Page+L_PageName) as URLPath from treeTable " ); InitWebListGroup( this .wlbLeft.Groups, " 0 " ,dt); }
//
添加组
private
void
InitWebListGroup(Infragistics.WebUI.UltraWebListbar.Groups Gps,
string
pID,DataTable data)
...
{ Infragistics.WebUI.UltraWebListbar.Group tmpGp; DataRow [] rows = data.Select( " P_L_ID=0 " ); foreach (DataRow row in rows) ... { tmpGp = new Infragistics.WebUI.UltraWebListbar.Group(); tmpGp.Key = row[ " L_ID " ].ToString(); tmpGp.Text = row[ " L_Name " ].ToString(); Gps.Add(tmpGp); InitWebListItems(tmpGp.Items,tmpGp.Key.ToString(),data); tmpGp.TextAlign = " Center " ; } }
//
添加组成员
private
void
InitWebListItems(Infragistics.WebUI.UltraWebListbar.Items items,
string
pID,DataTable data)
...
{ Infragistics.WebUI.UltraWebListbar.Item item; DataRow [] rows = data.Select( " P_L_ID=' " + pID + " ' " ); foreach (DataRow row in rows) ... { item = new Infragistics.WebUI.UltraWebListbar.Item(); item.Key = row[ " L_ID " ].ToString(); item.Text = row[ " L_Name " ].ToString(); item.TargetUrl = row[ " URLPath " ].ToString(); item.TargetFrame = " main " ; items.Add(item); } }
-------------------------------------------------------------------------------------
以下是我改写的,只用改一个 DataBindWebList() 方法就OK了
-------------------------------------------------------------------------------------
private void DataBindWebList() { SqlConnection dc = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDB"].ConnectionString.ToString()); DataTable dt=new DataTable ();
SqlDataAdapter myDp = new SqlDataAdapter("select L_ID,L_Name,P_L_ID,(L_Page+L_PageName) as URLPath from treeTable", dc); myDp.Fill(dt); InitWebListGroup(this.UltraWebListbar1.Groups, "0",dt); }