手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp.Net编程>列表

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

来源:互联网 作者:west263.com 时间:2008-02-22
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

程序代码如下:

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

}

}

}

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

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!