SharePoint 2013 如何使用TaxonomyWebTaggingControl 控件
在该文章中,我将介绍如何使用TaxonomyWebTaggingControl控件, 首先我相信您已经在SharePoint Managed Metadata Service里定义Term Sets,如果没有,请先定义您的Term Sets(可以参考该文章how to create metadata column), 该控件能帮助我们显示/设置各种Terms。
其次我们需要了解Managed Metadata的结构,请看以下图,您可以清晰地看到每一个结构(Term Store -> Group -> Term Set -> Terms),接下来我们进入主题, 该如何使用TaxonomyWebTaggingControl 控件绑定这些数据呢,在该案例中我们绑定Product Type Group的所有数据。

根据以下步骤:
- 在我们的设计页面中定义注册Microsoft.SharePoint.Taxonomy控件
<%@ Register TagPrefix="Taxonomy" Namespace="Microsoft.SharePoint.Taxonomy" Assembly="Microsoft.SharePoint.Taxonomy, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
2. 在内容部分添加TaxonomyWebTaggingControl控件
<Taxonomy:TaxonomyWebTaggingControl ID="twtc_productType" runat="server"></Taxonomy:TaxonomyWebTaggingControl>
3. 在后台绑定数据(从Managed Metadata Service中获取Group的数据)
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy; /// <summary>
/// TaxonomyWebTaggingControl Bind
/// </summary>
/// <param name="productTypeControl">TaxonomyWebTaggingControl Control</param>
public static void ProductTypeBind(TaxonomyWebTaggingControl productTypeControl)
{
// Open the site
using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb web = site.OpenWeb())
{
TaxonomySession session = new TaxonomySession(site);
// Get the Term Store node from Managed Metadata Service
TermStore termStore = null;
if (session.TermStores != null && session.TermStores.Count > )
{
termStore = session.TermStores["Managed Metadata Service"]; //if you a custom meta service you should change name.
}
if (termStore != null)
{
//Guid anchorId = new Guid();
Group group = termStore.Groups["Product Type"]; // Get the Group node from Managed Metadata Service
productTypeControl.SspId.Add(termStore.Id); // do it for all termsets
foreach (TermSet item in group.TermSets)
{
productTypeControl.TermSetId.Add(item.Id); // Add the Term
/* This could be achieved by setting AnchorId property for TaxonomyWebTaggingControl control that allows to specify ID of parent Term for any valid value in control.
foreach (Term term in item.Terms)
{
if (term.Name == ManagedMetadataType.TermName)
{
anchorId = term.Id;
break;
}
} */
} //productTypeControl.AnchorId = anchorId;
productTypeControl.GroupId = group.Id;
productTypeControl.IsAddTerms = false;
}
}
}
}
以上代码将可以获取Product Type(defined by GB/T 13702-1992)节点的数据, 可以查看一下效果图

有些朋友会问是否可以根据Term 节点作为父节点显示?对于该问题的回答是可以, 比如我想以All为父节点,我们仅仅通过该控件中的AnchorId属性,将All的id赋值给AnchorId即可,留心的朋友会发现在以上代码中注释部分就是实现该功能

如果有大牛认为有更好的idea, 请提供您宝贵的建议供大家学习,谢谢
SharePoint 2013 如何使用TaxonomyWebTaggingControl 控件的更多相关文章
- sharepoint 2010 列表数据分页控件介绍 pagination UserControl
转:http://blog.csdn.net/chenxinxian/article/details/8714391 这里主要是介绍下最近开发的一个sharepoint列表或者文档库的分页控件,并且把 ...
- SharePoint 2007 页面及用户控件
页面: <%@ Assembly Name="HP.EUSM.Self-ServiceUpgradeQuota.SPCustomAction, Version=1.0.0.0, Cul ...
- SharePoint 2010 master page 控件介绍(1)
转:http://blog.csdn.net/lgm97/article/details/6409204 以下所有的内容都是根据Randy Drisgill (MVP SharePoint Serve ...
- Sharepoint2013:日期控件报错
1 问题 1> 在sharepoint中的,日期控件(DateTimeControl),日期过滤控件(Date Filter)和SPListViewFilter等包含日期组件的控件,在特定情况下 ...
- SharePoint 2013 新功能探索 之 标注控件
SharePoint 2013 引入了新的UI,同时也跟进了网络潮流,把应用最广泛的标注控件也引入到了SharePoint,先看两个应用 以上是两个开发当中经常会用到,下面就介绍一下如何开发相同 ...
- sharepoint 2013 附件控件FileUpload怎样检验是否为图片的方法
记录一下关于附件控件FileUpload怎样检验是否为图片的方法: function checkImg() { var fileObj =document.getElementById('<%= ...
- SharePoint 中用户控件的开发及应用
1.新建解决方案以及SharePoint项目,步骤比较简单略过,然后映射CONTROLTEMPLATES文件夹,在里面添加用户控件(仅场解决方案),如下图: 2.解决方案结构,如下图: 简单介绍一下, ...
- 2013 duilib入门简明教程 -- 自绘控件 (15)
在[2013 duilib入门简明教程 -- 复杂控件介绍 (13)]中虽然介绍了界面设计器上的所有控件,但是还有一些控件并没有被放到界面设计器上,还有一些常用控件duilib并没有提供(比如 ...
- Dynamic CRM 2013学习笔记(八)过滤查找控件 (类似省市联动)
我们经常要实现类似省市联动一样的功能,常见的就是二个查找控件,一个选择了省后,另一个市的查找控件就自动过滤了,只显示当前省下的市,而不是所有的市.当然这是最简单的,实际工作中还有更复杂的功能要通过过滤 ...
随机推荐
- 364. Nested List Weight Sum II
这个题做了一个多小时,好傻逼. 显而易见计算的话必须知道当前层是第几层,因为要乘权重,想要知道是第几层又必须知道最高是几层.. 用了好久是因为想ONE PASS,尝试过遍历的时候构建STACK,通过和 ...
- linux系统启动oracle
linux下启动oracle需要两步:一.启动监听 二.启动服务 一.启动监听 监听命令:lsnrctl ,具体使用方法如下 1.lsnrctl status:检查当前监听器的状态 2.lsnrct ...
- 【转】服务器证书安装配置指南(Weblogic)
服务器证书安装配置指南(Weblogic) 详情请点击: http://verisign.itrus.com.cn/html/fuwuyuzhichi/fuwuqizhengshuanzhuangpe ...
- MySQL slave状态之Seconds_Behind_Master
在MySQL的主从环境中,我们能够通过在slave上运行show slave status来查看slave的一些状态信息,当中有一个比較重要的參数Seconds_Behind_Master.那么你是否 ...
- 我的docker 使用笔记
0 容器启动 docker run image_name(镜像名称) echo "hello word" 1 启动容器 退出后 重新进入 方法一 sudo docker exec ...
- 详解 Spring 3.0 基于 Annotation 的依赖注入实现--转载
使用 @Repository.@Service.@Controller 和 @Component 将类标识为 Bean Spring 自 2.0 版本开始,陆续引入了一些注解用于简化 Spring 的 ...
- [转] What is the point of redux when using react?
As I am sure you have heard a bunch of times, by now, React is the V in MVC. I think you can think o ...
- json-lib-2.4-jdk15.jar maven
最近自己将一个web项目装换到使用mevan自动管理. 遇到了一个json包导入的问题.最终解决如下: <!-- https://mvnrepository.com/artifact/net.s ...
- Java基础知识强化10:Java中的中间缓存变量机制
1.对于自增运算++j与j++,由于加一的执行顺序不同,所以Java中有中间缓存变量来储存其单个表达式的值,而j的自增自减的结果依然保留在原来的变量储存区.因为本体是j的值,而单个表达式的值是中间产生 ...
- 关于css中伪类及伪元素的总结
css中的伪类和伪元素总是混淆,今天参考了很多资料,也查看了部分文档,现将伪类及伪元素总结如下: 一.由来: 伪类和伪元素的引入都是因为在文档树里有些信息无法被充分描述,比如CSS没有"段落 ...