C# 如何使用数据库中存储的数据创建多级菜单?
我有一些层次结构数据,我想在SharePoint网站上建立一个菜单。如何在SharePoint上使用此数据构建菜单 任何人都可以向我展示在SharePoint母版页上显示数据库数据的示例。实现这一点的“SharePoint方法”是创建自定义导航提供程序。以下是来自Microsoft站点的示例:C# 如何使用数据库中存储的数据创建多级菜单?,c#,asp.net,sharepoint,menu,sharepoint-2010,C#,Asp.net,Sharepoint,Menu,Sharepoint 2010,我有一些层次结构数据,我想在SharePoint网站上建立一个菜单。如何在SharePoint上使用此数据构建菜单 任何人都可以向我展示在SharePoint母版页上显示数据库数据的示例。实现这一点的“SharePoint方法”是创建自定义导航提供程序。以下是来自Microsoft站点的示例: using System; using System.Collections.Generic; using System.Text; using Microsoft.SharePoint.Publishi
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();
}
}
}
使用系统;
使用System.Collections.Generic;
使用系统文本;
使用Microsoft.SharePoint.Publishing;
使用Microsoft.SharePoint.Publishing.Navigation;
使用System.Web;
使用System.Web.UI.WebControl;
使用系统配置;
名称空间MyCustomNav
{
公共类导航:PortalItemApprovider
{
公共覆盖SiteMapNodeCollection GetChildNodes(System.Web.SiteMapNode
节点)
{
PortalSiteMapNode pNode=作为PortalSiteMapNode的节点;
if(pNode!=null)
{
if(pNode.Type==NodeType.Area)
{
//TODO:在此处调用数据库并根据查询创建节点。。
SiteMapNodeCollection nodeColl=base.GetChildNodes(pNode);
SiteMapNode childNode=新建SiteMapNode(此,
“,”,“微软”);
SiteMapNode childNode1=新建SiteMapNode(此,
“,”支持“);
添加(子节点);
SiteMapNodeCollection测试=新建SiteMapNodeCollection();
test.Add(childNode1);
childNode.ChildNodes=测试;
返回nodeColl;
}
其他的
返回base.GetChildNodes(pNode);
}
其他的
返回新的SiteMapNodeCollection();
}
}
}
这将转到web.config
<add name="MyCustomNavigationProvider" type="MyCustomNav.Navigation, MyCustomNav"
NavigationType="Current" />
<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"/>