您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
基于asp.net的webmenu的数据操作4
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:22:06

程序代码如下:

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.

      &nbs

[1] [2] 下一页


更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |