Conditional Formatting inside Repeater

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ratherbeehome
    New Member
    • Mar 2007
    • 1

    Conditional Formatting inside Repeater

    Hello,

    I am new to ASP .NET. I am using a repeater that lists data from a SQL database. In one column, I want to highlight the text in red if the text is "I"; highlight the text in green if text is "II" and highlight the text in blue if text is "III". I am fairly familiar with VB but not familiar with C# at all. Please help!
  • Queez
    New Member
    • Jul 2007
    • 24

    #2
    Hi, I'm surprised no-one's answered you in a whole year. You've probably worked something out or given up by now!

    Anyway, I had a similar problem recently and thought I should share my solution. It may be the wrong way to go about it, but it worked.

    Basically, I added a few extra columns to my dataset, having populated it with my data from the DB:

    Code:
    ds.Tables(0).Columns.Add("NewColumnName")
    Then cycled through my dataset and where I found the value I wanted to colour Green (in my case), I set the value in my new column to be the name of a specific CSS class I'd set up, e.g:

    Code:
    For Each r As Data.DataRow In ds.Tables(0).Rows
        If r("AColumn") IsNot DBNull.Value AndAlso CInt(r("AColumn") = SomeComparingValue Then
            r("NewColumnName") = "mycssclass"
        Else
            r("NewColumnName") = "myothercssclass"
        End If
    Next
    Finally in my ASPX file, I had the following in bits of my repeater:

    Code:
    ... class='<%#DataBinder.Eval(Container.DataItem, "NewColumnName")%>' ...
    It's a bit messy, but it works.

    Comment

    Working...