setting row color of data repeater according to field values
-
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") %>
-
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") %>
-
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") %>
Hi there. One way to do it - you could add a databinding expression to the
bgcolor
attribute of your<td>
tags in yourItemTemplate
. In this example I'm using a custom functionGetColor
and passing it the results of theDataBinder.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 SubFunction 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.
-
Hi there. One way to do it - you could add a databinding expression to the
bgcolor
attribute of your<td>
tags in yourItemTemplate
. In this example I'm using a custom functionGetColor
and passing it the results of theDataBinder.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 SubFunction 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.
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?
-
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?
Simply, set row's bgcolor instead of column - UTSAV
-
Simply, set row's bgcolor instead of column - UTSAV
hi utsav, up and running now.. ;) thanks..
-
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?
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.
-
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.
Hi mike i guess browsers after IE 4.0 supports it well, m i rite? UTSAV
-
Hi mike i guess browsers after IE 4.0 supports it well, m i rite? UTSAV
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.