SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a dynamic Spgridview. I add column in page load.

I use this code for add Hyperlinkfield in SPFieldType.URL :

string[] url = new string[1];
url[0] = field.InternalName;
HyperLinkField link = new HyperLinkField();
link.HeaderText = field.Title;
link.DataNavigateUrlFields = url;
link.DataNavigateUrlFormatString = "{0}";
link.DataTextField = field.InternalName;
link.SortExpression = field.InternalName;

my problem is : for example my url is "http://Test1.docx, http://Test1.docx".

I want navigateurl set "http://Test1.docx" .

share|improve this question
up vote 1 down vote accepted

The problem is that your field has the string representation of a SPFieldUrlValue which is "Url, Description"

Either you have to change the content of that column in the datasource or change to the NavigateUrl of the HyperLinkField in OnRowDataBound

To extract the url of the string use:

new SPFieldUrlValue(string).Url
share|improve this answer
Thanks a lot :) – ar.gorgin Apr 7 '12 at 5:20

Just the split the URL

string startText = "http://Test1.docx, http://Test1.docx";
string[] tempString = startText.Split(',');
link.NavigateUrl = tempString[0];
share|improve this answer
I created column dynamic ! – ar.gorgin Apr 5 '12 at 7:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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