1

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" .

2 Answers 2

1

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
0
0

Just the split the URL

string startText = "http://Test1.docx, http://Test1.docx";
string[] tempString = startText.Split(',');
link.NavigateUrl = tempString[0];
1
  • I created column dynamic !
    – ar.gorgin
    Commented Apr 5, 2012 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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