0

I am using spgridview to collect document information from multiple document libraries in my SharePoint 2010 publishing site.

When the column information is displayed, it seems that a GUID or something is displayed alongside the textual column name. for example:

Anaesthisiology|6bff78d4-ef67-440a-b0f5-1bd32e28c754

The following is my sourcecode for this logic:

        protected void Page_Load(object sender, EventArgs e)
    {
        getData();
    }

     public void getData()
     {
         DataTable dt = new DataTable();
         DataRow dr;
         DataColumn dc;

         SPSite curSite = SPContext.Current.Site;
         SPWebCollection subSites = curSite.AllWebs;

         dc = new DataColumn("Title", Type.GetType("System.String"));
         dt.Columns.Add(dc);
         dc = new DataColumn("SubSection", Type.GetType("System.String"));
         dt.Columns.Add(dc);
         dc = new DataColumn("SubSubSection", Type.GetType("System.String"));
         dt.Columns.Add(dc);
         dc = new DataColumn("Created", Type.GetType("System.DateTime"));
         dt.Columns.Add(dc);
         dc = new DataColumn("SiteUrl", Type.GetType("System.String"));
         dt.Columns.Add(dc);

         for (int i = 0; i < subSites.Count; i++)
         {
             SPListCollection lists = subSites[i].Lists;

             foreach (SPList list in lists)
             {
                 if (list.Title == "Clinical")
                 {
                     SPQuery myquery = new SPQuery();

                     myquery.Query = "<GroupBy><FieldRef Name='SubSection' /></GroupBy><OrderBy><FieldRef Name='SubSection' /></OrderBy>";

                     SPListItemCollection items = list.GetItems(myquery);

                     foreach (SPListItem item in items)
                     {
                         if (item != null)
                         {
                             dr = dt.NewRow();

                             dr["Title"] = item["Title"];                                 
                             dr["SubSection"] = item["SubSection"];
                             dr["SubSubSection"] = item["SubSubSection"];
                             dr["SiteUrl"] = subSites[i].Url + 
                             "/DSTs/Forms/DispForm.aspx?ID=" 
                             + item["ID"].ToString(); ;

                             dt.Rows.Add(dr);
                         }
                     }
                 }
             }
         }

         dt.DefaultView.Sort = "SubSection";

         HyperLinkField colTitle = new HyperLinkField();
         colTitle.HeaderText = "Title";
         colTitle.DataTextField = "Title";
         string[] SiteUrl = { "SiteUrl" };
         colTitle.DataNavigateUrlFields = SiteUrl;
         colTitle.NavigateUrl = "SiteUrl";
         spLibraryView.Columns.Add(colTitle);

         BoundField colSubSection = new BoundField();
         colSubSection.DataField = "SubSection";
         colSubSection.HeaderText = "SubSection";
         spLibraryView.Columns.Add(colSubSection);

         BoundField colSubSubSection= new BoundField();
         colSubSubSection.DataField = "SubSubSection";
         colSubSubSection.HeaderText = "SubSubSection";
         spLibraryView.Columns.Add(colSubSubSection);

         spLibraryView.AllowGrouping = true;
         spLibraryView.AllowGroupCollapse = true;
         spLibraryView.GroupField = "SubSection";

         spLibraryView.DataSource = dt;
         spLibraryView.DataBind();
     }

I added a watch to the value item["SubSection"] and it shows the following:

{Anaesthisiology|6bff78d4-ef67-440a-b0f5-1bd32e28c754}

drilling down, the Label property shows:

"Anaesthisiology"

Why does the GUID show, and if I am using the wrong property how might I access the "Label" property via code?

Thanks

0

Why not use a Regex.Replace call to parse?

string strSubSection = item["SubSection"];
Regex.Replace(strSubSection, "((.*))|.*", "$1");
dr["SubSection"] = strSubSection;
  • Yes, i could definately do that - thank you. It does seem somewhat of a 'bandaid fix' though. I am still curious as to why this is showing up in the first place, and how to just pull the column name without the GUID. If I cannot, I will use your method - thx! – Kolten Feb 28 '12 at 17:36
  • You'll have to add a using statement to the top of the file: using System.Text.RegularExpressions; – RJ Cuthbertson Feb 28 '12 at 17:37
  • I use this all the time to parse data returned from SP lists. – RJ Cuthbertson Feb 28 '12 at 17:37
  • ok this is normal when working with lists? I was unaware - this is the first actual coding piece I have worked on that uses SPlists. Thanks! – Kolten Feb 28 '12 at 17:41
  • You can use regular expressions in many languages. They're very powerful. Take a look here: regular-expressions.info – RJ Cuthbertson Feb 28 '12 at 17:46
0

THis is because the field value is a TaxonomyFieldValue. It's tostring method will return the contents of the field, which is stored in the format TERMLABEL|TERMID.

You'd have to add a OnRowDatabound event to your grid, get the currently bound dataitem, get the correct field, the cast to TaxonomyFieldValue, and display the TermLabel only

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.