I set up a gridview to display search results on a webpage.
I have the code below that is “supposed” to replace any instance of a search term, with a bolded version of that word.
I’ve tried many different versions, but nothing is working.
Private Sub gvSearchResults_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvSearchResults.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
For Each cell As TableCell In e.Row.Cells
If cell.Text.Contains(searchTerm) Then
cell.Text = cell.Text.Replace(Session("SearchTerm"), "<span style='font-weight: bold;'>" & Session("SearchTerm") & "</span>")
End If
Next
End If
End Sub
Is there anything missing in my logic?
Thanks!
If the
Cell.Textis blank, then likely the gridview is placing a Literal control in theCell.Controlscollection. You should put something like this in: