0

I had gone the route of creating a placeholder on the aspx page and then doing:

myPlaceHolder.Controls.Add(myTaxonomyControl);

but for some reason this doesn't do anything. No error and no control. Do I need to do anything special to add this type of control to a page?

2 Answers 2

1

This is the code I use:

var taxField = field as TaxonomyField; // the SPField the control should bind to
var session = new TaxonomySession(field.ParentList.ParentWeb.Site);
var store = session.TermStores[0];
var termSet = store.GetTermSet(taxField.TermSetId);
var taxonomyControl = new TaxonomyWebTaggingControl();
taxonomyControl.IsMulti = taxField.AllowMultipleValues;
taxonomyControl.IsAddTerms = termSet.IsOpenForTermCreation;
if (termSet.IsOpenForTermCreation)
{
  taxonomyControl.AllowFillIn = true;
}
taxonomyControl.TermSetId.Add(store.Id);
taxonomyControl.ID = "fld_" + taxField.InternalName;
taxonomyControl.FieldName = taxField.Title;
taxonomyControl.FieldId = taxField.Id.ToString();
taxonomyControl.SSPList = taxField.SspId.ToString();
taxonomyControl.AnchorId = taxField.AnchorId;
taxonomyControl.TermSetList = taxField.TermSetId.ToString();
if (!Page.IsPostBack)
{
  if (Item[taxField.InternalName] != null)
  {
    taxonomyControl.Text = Item[taxField.InternalName].ToString();
  }
}
fieldPanel.Controls.Add(taxonomyControl);
1
  • Where do you create the field? Some code seems to be missing Nov 12, 2014 at 14:39
0

You need to bind the term set to the TaxonomyWebTaggingControl so that it allows you to pick and display terms. See link below:

http://blog.bugrapostaci.com/2010/09/23/taxonomywebtaggingcontrol-sharepoint/

and

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.taxonomy.taxonomywebtaggingcontrol.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.