Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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;
grid.Columns.Add(link);

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

2 Answers 2

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

 
discard

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.