您的位置:首页精文荟萃软件资讯 → 基于asp.net的webmenu的数据操作4

基于asp.net的webmenu的数据操作4

时间:2004/10/8 13:17:00来源:本站整理作者:蓝点我要评论(0)

程序代码如下:


using System;


using System.Collections;


using System.ComponentModel;


using System.Data;


using System.Drawing;


using System.Web;


using System.Web.SessionState;


using System.Web.UI;


using System.Web.UI.WebControls;


using System.Web.UI.HtmlControls;


using System.Data.OleDb;


 


namespace WebApplication6


{


     ///


     /// WebForm1 的摘要说明。


     ///


     public class WebForm1 : System.Web.UI.Page


     {


         protected Coalesys.WebMenu.WebMenu csNetMenu;


    


         private void Page_Load(object sender, System.EventArgs e)


         {


              // 在此处放置用户代码以初始化页面


              csNetMenu.MenuBar.AbsoluteDockEnabled = false;


              csNetMenu.MenuBar.AbsoluteDragEnabled = false;


              csNetMenu.MenuBar.BackgroundColor = "";


              csNetMenu.MenuBar.OuterHighlightColor = "#666666";


              csNetMenu.MenuBar.OuterShadowColor = "#666666";


              csNetMenu.MenuBar.InnerShadowColor = "#F9F8F7";


              csNetMenu.MenuBar.HoverColor = "#dfdfdf";


              csNetMenu.MenuBar.SelectedColor = "#B6BDD2";


              csNetMenu.MenuBar.SelectedTextColor = "#000000";


              csNetMenu.BackgroundColor = "";


              csNetMenu.SelectedColor = "#B6BDD2";


              csNetMenu.OuterHighlightColor = "#c0c0c0";


              csNetMenu.OuterShadowColor = "#c0c0c0";


              csNetMenu.InnerShadowColor = "#808080";


              csNetMenu.PopupIcon = "./images/arrow-black.gif";


              csNetMenu.SelectedPopupIcon = "./images/arrow-white.gif";


              csNetMenu.ClearPixelImage = "./images/clearpixel.gif";          


 


              // Populate WebMenu


              LoadWebMenuData(csNetMenu);


         }


 


         //=============================================================================


         // LoadWebMenuData - load webmenu from database


         //


         // input:


         //  csWebMenu - [in] Coalesys.WebMenu.WebMenu object


         //


         // output:


         //   none


         //


         public void LoadWebMenuData(Coalesys.WebMenu.WebMenu csWebMenu)


         {


              Coalesys.WebMenu.Group csMenuGroup;


 


              // database info


              string dbConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";


              string dbPathString = Server.MapPath("./SelfReferencedTable.mdb");


              string dbSqlString = "SELECT * FROM Nodes ORDER BY ID";


 


              // Initiate OleDb interface


              OleDbConnection dbConn = new OleDbConnection(dbConnString + dbPathString);


              OleDbCommand dbComm = new OleDbCommand(dbSqlString, dbConn);


              OleDbDataAdapter dbAdapter = new OleDbDataAdapter();


 


              dbConn.Open();


 


              // Fill an ADO.NET DataSet


              DataSet ds = new DataSet();


              dbAdapter.SelectCommand = dbComm;


              dbAdapter.Fill(ds, "MenuItems");


 


              dbConn.Close();


 


              // Create the data relation between the ID and Parent_ID columns of the MenuItems table.


              // (this is the key to hierarchical navigating in a self-referencing table).


              DataRelation dr = ds.Relations.Add("MenuItemHierarchy",


                   ds.Tables["MenuItems"].Columns["ID"],


                   ds.Tables["MenuItems"].Columns["Parent_ID"]);


 


              // Start top-down navigation of the MenuItem rows.


              foreach(DataRow dbMenuItem in ds.Tables["MenuItems"].Rows)


              {


                   // If the Parent_ID colum is null, then this is a root menu item.


                   if(dbMenuItem.IsNull("Parent_ID"))


                   {


                       // Create a menu group for the root menu item


                       csMenuGroup = csWebMenu.Groups.Add();


                       csMenuGroup.Caption = dbMenuItem["Caption"].ToString();


 


                       // execute the recursive function to populate all it's children.


                       AddMenuItems(dbMenuItem.GetChildRows(dr), dr, csMenuGroup);


                   }


              }


         }


 


 


         //=============================================================================


         // AddMenuItems        - Recursive function to populate hierarchical Menu Items


         //                       from data rows that have parent/child relationships.


         //


         // input:


         //   dataRows      - [in] Child Rows


         //  dataRel            - [in] Data Relation


         //  webMenuGroup   - [in] WebMenu Group


         //


         // output:


         //   none


         //


         public void AddMenuItems(DataRow[] dataRows, DataRelation dataRel, Coalesys.WebMenu.Group webMenuGroup)


         {


              Coalesys.WebMenu.Item csMenuItem;


              Coalesys.WebMenu.Group csNestedMenuGroup;


              DataRow[] drChildren;


 


              foreach(DataRow dbMenuItem in dataRows)


              {


                   csMenuItem = webMenuGroup.Items.Add();


                   csMenuItem.Caption = dbMenuItem["Caption"].ToString();


                   csMenuItem.URL = dbMenuItem["URL"].ToString();


                   if (dbMenuItem["Enable"].ToString()=="True" )


                   {


                       csMenuItem.Enabled=true;


                   }


                   else


                   {


                       csMenuItem.Enabled=false;


                   }


                  


                   // check if this Item has children of it's own


                   drChildren = dbMenuItem.GetChildRows(dataRel);


                   // if so, create a group for the children and reenter this function.


                   if(drChildren.Length > 0)


                   {


                       csNestedMenuGroup = csMenuItem.AddGroup();


                       AddMenuItems(drChildren, dataRel, csNestedMenuGroup);


                   }


              }


         }


 


}



 


效果图如下:




相关阅读 Mac访问Windows共享文件夹Windows 7正版系统验证方法windows 8.1系统版本号查看方法Windows 8.1系统电话激活时无法输入微软返回代码解决方法Windows 8如何调整屏幕分辨率windows8.1磁盘占用100%解决方法Mac双系统如何删除Boot Camp安装的Windows分区Apple教你如何在Mac 上运行 Windows

文章评论
发表评论

热门文章 360快剪辑怎么使用 36金山词霸如何屏幕取词百度收购PPS已敲定!3

最新文章 微信3.6.0测试版更新了微信支付漏洞会造成哪 360快剪辑怎么使用 360快剪辑软件使用方法介酷骑单车是什么 酷骑单车有什么用Apple pay与支付宝有什么区别 Apple pay与贝贝特卖是正品吗 贝贝特卖网可靠吗

人气排行 xp系统停止服务怎么办?xp系统升级win7系统方电脑闹钟怎么设置 win7电脑闹钟怎么设置office2013安装教程图解:手把手教你安装与qq影音闪退怎么办 QQ影音闪退解决方法VeryCD镜像网站逐个数,电驴资料库全集同步推是什么?同步推使用方法介绍QQ2012什么时候出 最新版下载EDiary——一款好用的电子日记本