I am using an ASP.net gridview. The datasource is SPList.Items.GetDataTable().

The gridview is working fine; however, lookup and multilookup columns display as "id;#value". Is there any way to just show the value?


Here is how I solved this issue:

<asp:TemplateField HeaderText="Campaign Members">
        <%# RemoveCharacters(Eval("CampaignMembers").ToString())%>

Make sure declare using System.Text.RegularExpression;:

protected string RemoveCharacters(object String)
    string s1 = String.ToString();
    string newString = Regex.Replace(s1, @"#[\d-];", string.Empty);
    newString = Regex.Replace(newString, "#", " ");
    return newString.ToString();

use SPBoundField in your gridview instead of BoundField

  • Okay. I tried SPGridView and spboundfield. I am still seeing the issue with lookupMulti where id;#value is showing when I have multiple values selected in the lookupmulti column.
    – Jamil Ferdaus
    Nov 28 '10 at 7:04

Alternatively, you could use SPFieldLookupValue (for a single lookup) and SPFieldLookupValueCollection (for a multi-lookup) to parse the field values using SharePoint's built-in methods for processing them.

Here is a revised version of your function for single lookups:

protected string RemoveCharacters(string fieldValue)
    SPFieldLookupValue value = new SPFieldLookupValue(fieldValue);
    return value.LookupValue;

I've also turned the parameter into a string since your XML passes one in.

Details on processing multiple lookups (and more) can be found in my blog article:

Easily accessing Lookup and User fields

Your Answer

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