论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Asp.net教程
Tag:静态页面,treeview,gridview,repeater,dataset,sqldatareader,ado.net,上传,三层,ajax,xml,留言本,新闻发布,商城,注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,触发器,socket,form认证,登录,视频教程

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

文章类别:Asp.net | 发表日期:2008-10-5 21:54:14

程序代码如下:

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

                   }

              }

         }

 

}


 

效果图如下:


视频教程列表
文章教程搜索
 
Asp.net推荐教程
Asp.net热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058