Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlighting and Hyperlinking Datagrid Text! 3

Status
Not open for further replies.

adamroof

Programmer
Nov 5, 2003
1,107
US
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>
 
Nice use of regex!
 
Not clear what the problem is. You should re-phrase the question.
 
Its not a question, its a Helpful Tip, as indicated by the Lightbulb.

Hover over the Show First at the forum index and will display all de options!
 
Thanks, I now know what those icons represent.
 
oops, forgot the css highlight...
Code:
.highlight 
	{
	text-decoration: none;
	color:black;
	background:yellow;
	}
i use external files...
Code:
<head>
    <title>Blade Search </title>
    <link rel="stylesheet" type="text/css" media="screen" href="css\page.css">
    <link rel="stylesheet" type="text/css" media="handheld" href="css\mobile.css" />

    <script src="js/page.js" type="text/javascript"></script>

</head>
 
UPDATE:

use this search_str to complete URL's with querystrings...
Code:
Search_Str = "\w*[\://]*\w+\.\w+\.\w+[/\w+]*[&?=.\w+]*"
It was cutting off when it saw a ?, &, or =
 
thats what got me rolling, and i added the URL finding and linking functionality to it.

wazzur point?
 
wazzur point?
No point, I was just pointing future readers of this post to the article in case they wanted to read up on what the code does.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top