基于asp.net的webmenu的数据操作4
2008-02-22 09:27:23来源:互联网 阅读 ()
程序代码如下:
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);
}
}
}
//=============================================================================
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 基于asp.net的webmenu的数据操作5 2008-02-22
- 基于asp.net的webmenu的数据操作3 2008-02-22
- 基于asp.net的webmenu的数据操作2 2008-02-22
- 基于asp.net的webmenu的数据操作1 2008-02-22
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash