Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. setting row color of data repeater according to field values

setting row color of data repeater according to field values

Scheduled Pinned Locked Moved ASP.NET
questioncsharpasp-netdocker
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MagicGirL83
    wrote on last edited by
    #1

    hi..how can i set the row color of a data repeater in asp.net/vb.net for example, on a record, it sees a "FATAL" on the value of the field and i want to color the row RED. if it sees "WARNING" then color yellow.. how can i do that in a data repeater? a sample code would help to get me started.. thanks.. what i have is: Sub Page_Load(sender As Object, e As EventArgs) Dim myConnection As SqlConnection Dim myCommand As SqlDataAdapter myConnection = New SqlConnection("Data Source................. myCommand = New SqlDataAdapter("SELECT * FROM [New Messages]", _ myConnection) Dim ds As Dataset = new DataSet() myCommand.Fill(ds) MyRepeater.DataSource = ds MyRepeater.DataBind() end sub

    Resource Name

    Status

    <%# DataBinder.Eval(Container.DataItem, "SenderName") %>

    <%# DataBinder.Eval(Container.DataItem, "Subject") %>

    T M 2 Replies Last reply
    0
    • M MagicGirL83

      hi..how can i set the row color of a data repeater in asp.net/vb.net for example, on a record, it sees a "FATAL" on the value of the field and i want to color the row RED. if it sees "WARNING" then color yellow.. how can i do that in a data repeater? a sample code would help to get me started.. thanks.. what i have is: Sub Page_Load(sender As Object, e As EventArgs) Dim myConnection As SqlConnection Dim myCommand As SqlDataAdapter myConnection = New SqlConnection("Data Source................. myCommand = New SqlDataAdapter("SELECT * FROM [New Messages]", _ myConnection) Dim ds As Dataset = new DataSet() myCommand.Fill(ds) MyRepeater.DataSource = ds MyRepeater.DataBind() end sub

      Resource Name

      Status

      <%# DataBinder.Eval(Container.DataItem, "SenderName") %>

      <%# DataBinder.Eval(Container.DataItem, "Subject") %>

      T Offline
      T Offline
      Timcyspet
      wrote on last edited by
      #2

      Hi try to give bgcolor in TR tag bye timcyspet

      1 Reply Last reply
      0
      • M MagicGirL83

        hi..how can i set the row color of a data repeater in asp.net/vb.net for example, on a record, it sees a "FATAL" on the value of the field and i want to color the row RED. if it sees "WARNING" then color yellow.. how can i do that in a data repeater? a sample code would help to get me started.. thanks.. what i have is: Sub Page_Load(sender As Object, e As EventArgs) Dim myConnection As SqlConnection Dim myCommand As SqlDataAdapter myConnection = New SqlConnection("Data Source................. myCommand = New SqlDataAdapter("SELECT * FROM [New Messages]", _ myConnection) Dim ds As Dataset = new DataSet() myCommand.Fill(ds) MyRepeater.DataSource = ds MyRepeater.DataBind() end sub

        Resource Name

        Status

        <%# DataBinder.Eval(Container.DataItem, "SenderName") %>

        <%# DataBinder.Eval(Container.DataItem, "Subject") %>

        M Offline
        M Offline
        Mike Ellison
        wrote on last edited by
        #3

        Hi there. One way to do it - you could add a databinding expression to the bgcolor attribute of your <td> tags in your ItemTemplate. In this example I'm using a custom function GetColor and passing it the results of the DataBinder.Eval expression for the field.

        <ItemTemplate>
        <tr>
        <td bgcolor='<%# GetColor(DataBinder.Eval(Container.DataItem, "Subject").ToString()) %>'>
        <%# DataBinder.Eval(Container.DataItem, "SenderName") %>
        </td>
        <td bgcolor='<%# GetColor(DataBinder.Eval(Container.DataItem, "Subject").ToString()) %>'>
        <%# DataBinder.Eval(Container.DataItem, "Subject") %>
        </td>
        </tr>
        </ItemTemplate>

        Then you could define GetColor() in your server script block like this:

        <script language="VB" runat="server">

        Sub Page_Load(sender As Object, e As EventArgs)
        ...
        End Sub

        Function GetColor(subject as string) as string
        If (subject.IndexOf("WARNING") >= 0) Then
        return "yellow"
        Else If (subject.IndexOf("FATAL") >=0) Then
        return "red"
        Else
        return "white"
        End If
        End Function

        </script>

        See if that helps.

        M 1 Reply Last reply
        0
        • M Mike Ellison

          Hi there. One way to do it - you could add a databinding expression to the bgcolor attribute of your <td> tags in your ItemTemplate. In this example I'm using a custom function GetColor and passing it the results of the DataBinder.Eval expression for the field.

          <ItemTemplate>
          <tr>
          <td bgcolor='<%# GetColor(DataBinder.Eval(Container.DataItem, "Subject").ToString()) %>'>
          <%# DataBinder.Eval(Container.DataItem, "SenderName") %>
          </td>
          <td bgcolor='<%# GetColor(DataBinder.Eval(Container.DataItem, "Subject").ToString()) %>'>
          <%# DataBinder.Eval(Container.DataItem, "Subject") %>
          </td>
          </tr>
          </ItemTemplate>

          Then you could define GetColor() in your server script block like this:

          <script language="VB" runat="server">

          Sub Page_Load(sender As Object, e As EventArgs)
          ...
          End Sub

          Function GetColor(subject as string) as string
          If (subject.IndexOf("WARNING") >= 0) Then
          return "yellow"
          Else If (subject.IndexOf("FATAL") >=0) Then
          return "red"
          Else
          return "white"
          End If
          End Function

          </script>

          See if that helps.

          M Offline
          M Offline
          MagicGirL83
          wrote on last edited by
          #4

          hi mike, cool..:) thanks.. i'm up there.. but it only highlighted the column that has the fatal or warning string.. what about highlighting the whole row?

          U M 2 Replies Last reply
          0
          • M MagicGirL83

            hi mike, cool..:) thanks.. i'm up there.. but it only highlighted the column that has the fatal or warning string.. what about highlighting the whole row?

            U Offline
            U Offline
            utsav_verma
            wrote on last edited by
            #5

            Simply, set row's bgcolor instead of column - UTSAV

            M 1 Reply Last reply
            0
            • U utsav_verma

              Simply, set row's bgcolor instead of column - UTSAV

              M Offline
              M Offline
              MagicGirL83
              wrote on last edited by
              #6

              hi utsav, up and running now.. ;) thanks..

              1 Reply Last reply
              0
              • M MagicGirL83

                hi mike, cool..:) thanks.. i'm up there.. but it only highlighted the column that has the fatal or warning string.. what about highlighting the whole row?

                M Offline
                M Offline
                Mike Ellison
                wrote on last edited by
                #7

                Setting the <tr> row color is a good suggestion, and probably works just fine with modern browsers (older browsers vary in their support for <tr> styling). That's why in the example I used the bgcolor for both <td> cells.

                U 1 Reply Last reply
                0
                • M Mike Ellison

                  Setting the <tr> row color is a good suggestion, and probably works just fine with modern browsers (older browsers vary in their support for <tr> styling). That's why in the example I used the bgcolor for both <td> cells.

                  U Offline
                  U Offline
                  utsav_verma
                  wrote on last edited by
                  #8

                  Hi mike i guess browsers after IE 4.0 supports it well, m i rite? UTSAV

                  M 1 Reply Last reply
                  0
                  • U utsav_verma

                    Hi mike i guess browsers after IE 4.0 supports it well, m i rite? UTSAV

                    M Offline
                    M Offline
                    Mike Ellison
                    wrote on last edited by
                    #9

                    Hi Utsav - you may be right... I don't remember the point where it was supported widely. I guess I just got used to setting the colors on the cells from way back when.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups