For my situation, i have a searchable datagrid via textbox, as the results display, it highlights via the span tags. If there is no searching, then i make all hyperlinkable things hyperlinks!
Code:
Public searchword as string
Sub Bind_Grid()
sSql = "SELECT * FROM tblOne"
If Trim(txtSearch.Text) <> "" Then
searchword = txtSearch.Text
sSql += " WHERE field LIKE '%" & searchword & "%'
End If
'Bind Your DG
End Sub
Function Highlight(Search_Str as String, InputTxt as String, StartTag as String, EndTag as String) As String
If Search_Str = "" Then
Search_Str = "\w*[\://]*\w+\.\w+\.\w+[/\w+]*[.\w+]*"
Return Regex.Replace(InputTxt, "\b(" & Search_Str & ")\b", "<a href='" & "$1" & "' target=_blank>" & "$1" & "</a>", RegexOptions.IgnoreCase)
Else
Return Regex.Replace(InputTxt, "\b(" & Regex.Escape(Search_Str) & ")\b", StartTag & "$1" & EndTag, RegexOptions.IgnoreCase)
End If
End Function
Code:
<asp:TemplateColumn HeaderText="Description">
<ItemTemplate>
<%# Highlight(searchword, DataBinder.Eval(Container.DataItem,"IncDesc"), "<span class=highlight>", "</span>") %>
</ItemTemplate>