Skip to content

Change specific words color in gridview

kavita

Asked Jul 6, 2007, 12:30 AM EDT2 answers
Share
LinkedInX
hi friends this is kavita can any body tell me how to change specific string color at runtime i.e. I have a field in database "detail" and I m showing it into gridview by using in a table like this: ......... <%#Container.DataItem("detail")%> and I want some special word which is enter by user are display in blue color. like if user enter"computer" and "detail"(it is a database field) contain "computer is a good" then in gridview the word"computer" display in blue color. please give me answer? can any body help me?

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    1.You first design a richText that display computer
    2.You Add this component to gridview's DataGridTableStyle To display it
    0
  • 0
    thanks luo I have done it in this way

    Public Function Highlight(ByVal InputTxt As String) As String

    Dim i As Integer

    Dim Search_Str As String = key

    Dim arr_color As String()

    Dim highlight_str As String = ""

    highlight_str = InputTxt

    arr_color = Search_Str.Split(" ")

    For i = 0 To UBound(arr_color)

    ' Setup the regular expression and add the Or operator.

    Dim RegExp As Regex = New Regex((arr_color(i).Trim()).Replace(" ", "").Trim(), RegexOptions.IgnoreCase)

    ' Highlight keywords by calling the MatchEvaluator delegate each time a keyword is found.

    highlight_str = RegExp.Replace(highlight_str, New MatchEvaluator(AddressOf ReplaceKeyWords))

    ' Set the Regex to nothing.

    RegExp = Nothing

    Next

    Highlight = highlight_str

    End Function

    Public Function ReplaceKeyWords(ByVal m As Match) As String

    Return "" & m.Value & ""

    End Function

    and it's working

    0