How can I display the field as a link in the DataGrid? If may or may not be stored in the ‘http://’ format.

Platform: ASP.NET| Category: DataGrid

<asp:DataGrid id='DataGrid1' AutoGenerateColumns='False' runat='server'>
	<Columns>
	<asp:TemplateColumn HeaderText='Link'>
		<ItemTemplate>
			<asp:HyperLink Runat =server NavigateUrl =’<%#GetURL(DataBinder.Eval(Container.DataItem, 'RegionDescription').ToString())%>’ ID='Hyperlink1'>
				<%#DataBinder.Eval(Container.DataItem, 'RegionDescription')%>
			</asp:HyperLink>
		</ItemTemplate>
	</asp:TemplateColumn>
	</Columns>
</asp:DataGrid>

VB.NET


Protected Function GetURL(ByVal fldval As String) As String
	If fldval.IndexOf('http://', 0, fldval.Length) = 0 Then
	            Return fldval
	Else
	            Return 'http://' + fldval
	End If
End Function ’GetURL

C#


protected	string GetURL (string fldval   )  
{
	if  (fldval.IndexOf ( 'http://' , 0, fldval.Length ) ==0)
	{
		return fldval;
	}
	else
	{
		return 'http://' + fldval;
	} 
}

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.