Data operation based on ASP.NET WebMenu (4)

zhaozj2021-02-16  53

The program code is as follows:

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

{

///

/// WebForm1 summary description.

///

Public class Webform1: System.Web.ui.page

{

Protected coalesys.webmenu.webmenu CsnetMenu;

Private Void Page_Load (Object Sender, System.EventArgs E)

{

/ / Place the user code here to initialize the page

CsNetMenu.menubar.absoluteDockenabled = false;

CsNetMenu.menubar.absoluteragenabled = 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.SelectedPopupffon = "./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 loadingWebmenudata (coalesys.webmenu.webmenu cswarebmenu)

{

Coalentsys.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, the this is a root menu it.

IF (DBMENUITEM.INULL ("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, Co., Ltd. WebMenu.group WebMenugroup)

{

Coalentsys.webmenu.Item CsmenuItem

Coalentsys.webmenu.group csnestedmenugroup;

Datarow [] DRCHILDREN;

Foreach (DataRow DBMenuItem in Datarows)

{

Csmenuitem = WebMenuGroup.Items.Add ();

Csmenuitem.caption = dbmenuitem ["caption"]. TOSTRING ();

Csmenuitem.ur = 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 referid.

IF (DRCHILDREN.LENGTH> 0)

{

CsnestedMenuGroup = csmenuitem.addgroup ();

AddMenuItems (DRCHILDREN, DATAREL, CSNESTEDMENUGROUP);

}

}

}

}

The effect is as follows:

转载请注明原文地址:https://www.9cbs.com/read-22104.html

New Post(0)