文章分类 | 推荐文章 | 最新文章 | 热点文章 | 最新软件 | 国产软件 | 国外软件 | 汉化补丁 | 设为首页 | 加入收藏
业界资讯 | 图形图像 | 操作系统 | 网络冲浪 | 工具软件 | 办公软件 | 媒体动画 | 精文荟萃 | 认证考试 | 网站建设 | 技术开发 | 专栏
当前位置:abcdown网络学院网络编程Asp.Net基于asp.net的webmenu的数据操作4
精品广告
推荐TOP10
·asp.net创建文件夹的IO类的问题
·ASP.NET 2.0 多文件上传小经验
·asp.net常用代码
·Asp.net cache 简述
·技巧实例:ASP.NET生成静态页面实现方法
·ASP.NET、JSP及PHP之间的抉择
·.net基础知识错误注意二十二点知识
·asp.net2.0学习历程 菜鸟到中级程序员的飞跃
·.NET基础知识-什么是.NET
·初学C#+ASP.NET+Oracle时积累的备忘点滴
阅读TOP10
·使用ASP.NET2.0的ReportViewer查看RDLC报表
·打造一个通用ASP.NET数据分页控件
·asp.net结合html,javascript实现无刷新跨域数据提交
·Asp.Net中使用水晶报表
·ASP.NET2.0下含有DropDownList的GridView编辑、删除的完整例子!
·ASP.NET 2.0 多文件上传小经验
·Asp.net cache 简述
·用http代理下载sourceforge的cvs仓库[原理+C#代码]
·asp.net常用代码
·利用.net反射动态调用指定程序集的中的方法

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

日期:2005年5月4日 作者:清风网络学院 查看:[大字体 中字体 小字体]


程序代码如下: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

{

     /// <summary>

     /// WebForm1 的摘要说明。

     /// </summary>

     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);

                   }

              }

         }

 

}



[1] [2] 下一页 

上一篇:基于asp.net的webmenu的数据操作3

下一篇:基于asp.net的webmenu的数据操作5


相关软件: 相关文章:
·基于asp.net的webmenu的数据操作5
·基于asp.net的webmenu的数据操作4
·基于asp.net的webmenu的数据操作3
·基于asp.net的webmenu的数据操作2
·基于asp.net的webmenu的数据操作1

特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
[打印本页] [关闭窗口] 转载请注明来源:http://www.abcdown.net
首页 | 本站声明 | 下载帮助 | 发布软件 |
中文版权所有:ABC学院 浙ICP备05000717号