(Web Menu) ComponentArt. Menu用法

來源:互聯網
上載者:User

前一些時間在一個項目中想用一個類似C/S架構的Menu菜單功能,但是自己在此之前沒有弄過,不會。於是Google,沒有找到自己理想的控制項,後一為朋友給了一個控制項。效果很是不錯,我想也有和我一樣的朋友會需要她,先將其拿來和大家一起分享。在這裡,我介紹一下ComponentArt. Menu的用法.

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 Web_Menu
{
    public partial class WebForm2 : System.Web.UI.Page
    {

        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack) buildMenu();
        }

        private void buildMenu()
        {
            OleDbConnection dbCon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("siteMap.mdb"));
            dbCon.Open();

            OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM SiteMap ORDER BY NodeId", dbCon);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            ds.Relations.Add("NodeRelation", ds.Tables[0].Columns["NodeId"], ds.Tables[0].Columns["ParentNodeId"]);

            foreach (DataRow dbRow in ds.Tables[0].Rows)
            {
                if (dbRow.IsNull("ParentNodeId"))
                {
                    ComponentArt.Web.UI.MenuItem newItem = CreateItem(dbRow);
                    Menu1.Items.Add(newItem);
                    PopulateSubMenu(dbRow, newItem);
                }
            }
        }

        private void PopulateSubMenu(DataRow dbRow, ComponentArt.Web.UI.MenuItem item)
        {
            foreach (DataRow childRow in dbRow.GetChildRows("NodeRelation"))
            {
                ComponentArt.Web.UI.MenuItem childItem = CreateItem(childRow);
                item.Items.Add(childItem);
                PopulateSubMenu(childRow, childItem);
            }
        }

        private ComponentArt.Web.UI.MenuItem CreateItem(DataRow dbRow)
        {
            ComponentArt.Web.UI.MenuItem item = new ComponentArt.Web.UI.MenuItem();
            item.Text = dbRow["Text"].ToString();
            item.NavigateUrl = dbRow["NavigateUrl"].ToString();
            item.LookId = dbRow["LookId"].ToString();
            item.Look.LeftIconUrl = dbRow["LeftIcon"].ToString();
            item.Look.HoverLeftIconUrl = dbRow["LeftIconHover"].ToString();
            item.Look.RightIconUrl = dbRow["RightIcon"].ToString();
            item.Look.HoverRightIconUrl = dbRow["RightIconHover"].ToString();
            return item;
        }
    }
}
效果如下:

如需要,我發給他。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.