In this article, I'll show you how to use the Taxonomywebtaggingcontrol control, first I believe you've defined term sets in the SharePoint Managed Metadata service, and if not, define your term Sets (you can refer to the article How to create Metadata column), which helps us to display/set various terms.
Next we need to understand the structure of the managed metadata, so you can see clearly each structure (term Set--Terms, term Store), then we go to the topic, How do I bind this data using the Taxonomywebtaggingcontrol control, in which we bind all the data of the product Type group.
Follow these steps:
- Define the Register Microsoft.SharePoint.Taxonomy control in our design page
<%@ Register TagPrefix="Taxonomy"Namespace="Microsoft.SharePoint.Taxonomy"Assembly="Microsoft.SharePoint.Taxonomy, version=15.0.0.0, culture=neutral, publickeytoken=71e9bce111e9429c" %>
2. Add Taxonomywebtaggingcontrol controls in the content section
<ID= "Twtc_producttype" runat= "Server"></ Taxonomy:taxonomywebtaggingcontrol >
3. Bind data in the background (get group data from managed Metadata service)
1 usingMicrosoft.SharePoint;2 usingMicrosoft.SharePoint.Taxonomy;3 4 /// <summary>5 ///Taxonomywebtaggingcontrol Bind6 /// </summary>7 /// <param name= "Producttypecontrol" >Taxonomywebtaggingcontrol Control</param>8 Public Static voidProducttypebind (Taxonomywebtaggingcontrol producttypecontrol)9 {Ten //Open the site One using(SPSite site =NewSPSite (SPCONTEXT.CURRENT.WEB.URL)) A { - using(SPWeb Web =site. OpenWeb ()) - { theTaxonomysession session =Newtaxonomysession (site); - //Get The term Store node from Managed Metadata Service -TermStore TermStore =NULL; - if(session.) Termstores! =NULL&& session. Termstores.count >0) + { -TermStore = Session. termstores["Managed Metadata Service"];//If you a custom meta service, should change name. + } A if(TermStore! =NULL) at { - //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 IteminchGroup. Termsets) - { in PRODUCTTYPECONTROL.TERMSETID.ADD (item. ID); ADD The term - /*This could is achieved by setting Anchorid property for Taxonomywebtaggingcontrol control, allows to specify ID of valid value in control. to foreach (term in item.) Terms) + { - if (term. Name = = managedmetadatatype.termname) the { * Anchorid = term. Id; $ Break ;Panax Notoginseng } - } */ the } + A //Producttypecontrol.anchorid = Anchorid; theProducttypecontrol.groupid =Group. Id; +Producttypecontrol.isaddterms =false; - } $ } $ } -}
The above code will be able to obtain the product Type (defined by GB/T 13702-1992) node data, you can view
Some friends ask if they can be displayed as parent nodes based on the term node. The answer to this question is yes, for example, I want to use all as the parent node, we only assign the ID of all to Anchorid by using the Anchorid property in the control, and the attentive friend will find that the comment section in the above code is the implementation of the function
If Daniel thinks there is a better idea, please provide your valuable suggestions for everyone to learn, thank you
How SharePoint 2013 uses the Taxonomywebtaggingcontrol control