簡體   English   中英

如何使用數據庫中存儲的數據創建多級菜單?

[英]How to create multi-level menu using data stored in database?

我有一些要在SharePoint網站上構建菜單的層次結構數據。 如何在SharePoint上使用此數據構建菜單。

誰能給我看一個示例,該示例在SharePoint的母版頁上顯示數據庫數據。

“ Sharepoint方式”是通過創建自定義導航提供程序來實現的。 來自Microsoft網站的示例如下:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Publishing;
using Microsoft.SharePoint.Publishing.Navigation;
using System.Web;
using System.Web.UI.WebControls;
using System.Configuration;

namespace MyCustomNav
{
public class Navigation: PortalSiteMapProvider
{
public override SiteMapNodeCollection GetChildNodes(System.Web.SiteMapNode 
node)
{
PortalSiteMapNode pNode = node as PortalSiteMapNode;
if (pNode != null)
{
if (pNode.Type == NodeTypes.Area)
{
// TODO: Make your database call here and create the node based on your query..

SiteMapNodeCollection nodeColl = base.GetChildNodes(pNode);
SiteMapNode childNode = new SiteMapNode(this, 
"<http://www.microsoft.com>", "<http://www.microsoft.com>", "Microsoft");

SiteMapNode childNode1 = new SiteMapNode(this, 
"<http://support.microsoft.com>", "<http://support.microsoft.com>", "Support");

nodeColl.Add(childNode);

SiteMapNodeCollection test = new SiteMapNodeCollection();
test.Add(childNode1);
childNode.ChildNodes = test;

return nodeColl;
}
else
return base.GetChildNodes(pNode);
}
else
return new SiteMapNodeCollection();
}
}
}

這取決於您web.config

<add name="MyCustomNavigationProvider" type="MyCustomNav.Navigation, MyCustomNav" 
NavigationType="Current" />

這個asp控件

<SharePoint:AspMenu
ID="TopNavigationMenu"
  Runat="server"
  DataSourceID="topSiteMap1"
  EnableViewState="false"
  AccessKey="<%$Resources:wss,navigation_accesskey%>"
  Orientation="Horizontal"
  StaticDisplayLevels="1"
  MaximumDynamicDisplayLevels="3"
  DynamicHorizontalOffset="0"
  StaticPopoutImageUrl="/_layouts/images/menudark.gif"
  StaticPopoutImageTextFormatString=""
  DynamicHoverStyle-BackColor="#CBE3F0"
  SkipLinkText=""
  StaticSubMenuIndent="0"
  CssClass="ms-topNavContainer">
<StaticMenuStyle/>
<StaticMenuItemStyle CssClass="ms-topnav" ItemSpacing="0px"/>
<StaticSelectedStyle CssClass="ms-topnavselected" />
<StaticHoverStyle CssClass="ms-topNavHover" />
<DynamicMenuStyle BackColor="#F2F3F4" BorderColor="#A7B4CE" 
  BorderWidth="1px"/>
<DynamicMenuItemStyle CssClass="ms-topNavFlyOuts"/>
<DynamicHoverStyle CssClass="ms-topNavFlyOutsHover"/>
<DynamicSelectedStyle CssClass="ms-topNavFlyOutsSelected"/>
</SharePoint:AspMenu>
<asp:SiteMapDataSource
  ShowStartingNode="False"
  SiteMapProvider="MyCustomNavigationProvider"
  id="topSiteMap1"
  runat="server"
  StartFromCurrentNode="true"/>

全文在這里:

http://msdn.microsoft.com/en-us/library/cc789625%28v=office.14%29.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM