July 14, 2013

Asp:HyperLinkField Gives Undesirable URL


When using the ASP.NET HyperLinkField to display the SharePoint Hyperlink field, the HyperLinkField will concatenate the web address (URL) with a comma, a space and then the description.

<asp:HyperLinkField HeaderText="Detail" DataNavigateUrlFields="Detail" Text="Detail" />

The redundant portions are highlighted in Yellow.


Result link: http://sptest/Site1/Pages/MyRequest.aspx?RequestID=2/22/2013 2:35:06 PM, View


Result link on GridView:   http://www.google.com,%20http//www.google.com


Replace the HyperLinkField with a TemplateField control. The TemplateField control will host a hyperlink control where it manipulate the NavigateUrl parameter to extract only the actual URL before the comma ‘,’ from the SharePoint Hyperlink field.

<asp:TemplateField HeaderText="Detail">
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl='<%# ((string)Eval("Detail")).Split(new string[]{","}, StringSplitOptions.None)[0] %>' Text="View" Target="_blank" />

No comments:

Post a Comment