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:


The following is my sourcecode for this logic:

        protected void Page_Load(object sender, EventArgs e)

     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"));
         dc = new DataColumn("SubSection", Type.GetType("System.String"));
         dc = new DataColumn("SubSubSection", Type.GetType("System.String"));
         dc = new DataColumn("Created", Type.GetType("System.DateTime"));
         dc = new DataColumn("SiteUrl", Type.GetType("System.String"));

         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 + 
                             + item["ID"].ToString(); ;


         dt.DefaultView.Sort = "SubSection";

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

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

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

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

         spLibraryView.DataSource = dt;

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


drilling down, the Label property shows:


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



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; Feb 28 '12 at 17:37
  • I use this all the time to parse data returned from SP lists. 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 Feb 28 '12 at 17:46

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.