Hi!
I am trying to highlight the search query in a gridview like this:
This works like charm, but if the search string contains any special charachters like the norwegian
I am trying to highlight the search query in a gridview like this:
Code:
foo is the gridview
strQuery is the search string
Dim itm As Object
Dim cel As TableCell
Dim iHit As Integer
Dim strOriginal As String
Dim strStart As String
If Len(strQuery) > 0 Then
For Each itm In foo.Rows
For Each cel In itm.Cells
If cel.Text.ToLower.Contains(strQuery.ToLower) And cel.Text <> " " Then
strStart = ""
strOriginal = cel.Text
iHit = InStr(strOriginal.ToLower, strQuery.ToLower)
If iHit > 1 Then
strStart = Left(strOriginal, iHit - 1)
End If
cel.Text = strStart & "<span style=color:red;background-color:Lime;font-weight:bold>" & Mid(strOriginal, iHit, Len(strQuery)) & ""
cel.Text = cel.Text & Right(strOriginal, Len(strOriginal) - (iHit + Len(strQuery)) + 1)
End If
Next
Next
End If
This works like charm, but if the search string contains any special charachters like the norwegian