3

I have a taxonomy picker control which is multi-allow type. I want to populate the text of that control.

My code is:

BindTaxonomyControls();
SPWeb currentWeb = SPContext.Current.Web;
SPList pagesLibrary = ListHelper.GetListByUrl(currentWeb.Lists, ListNames.Pages);
if (pagesLibrary != null)
{                
    SPListItem currentPage = pagesLibrary.GetItemById(id);
    txtNewsTitle.Text = Convert.ToString(currentPage[FieldNames.Title]);
    if (currentPage[FieldNames.Offices] != null)
    {   
        TaxonomyFieldValueCollection officesValue = currentPage[FieldNames.Offices] as TaxonomyFieldValueCollection;

        if (officesValue != null)
        {
            foreach (TaxonomyFieldValue office in officesValue)
            {

                string.Concat(twtcOffices.Text, string.Format("{0}|{1}", Convert.ToString(office), Convert.ToString(office.TermGuid)));
            }
        }
    }
}
private void BindTaxonomyControls()
{
    try
    {
        SPSite site = SPContext.Current.Site;
        SPWeb web = site.RootWeb;
        TaxonomyField officeField = web.Fields.GetFieldByInternalName(FieldNames.Offices) as TaxonomyField;
        if (officeField != null)
        {
            twtcControl.TermSetId.Add(officeField.TermSetId);
            twtcControl.SspId.Add(officeField.SspId);
        }
    }
    catch (Exception ex)
    { }
    finally
    { }
}

I referred this post to assign the multiple values to the taxonomywebtaggingcontrol but I am not getting the field populated. What am I missing?

3

Looks like you forgot to specify TaxonomyWebTaggingControl value (see TaxonomyWebTaggingControl.Text Property):

Set values into this control as pairs of labels and GUIDs. The delimiter between a label and a GUID is the | character. When using multiple values, delimit them with a ; character. Example: term1|12345678-1234-1234-1234-123456789012;term2|87654321-4321-4321-4321-210987654321

In your case:

twtcOffices.Text = string.Concat(twtcOffices.Text, string.Format("{0}|{1}", Convert.ToString(office), Convert.ToString(office.TermGuid)));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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