Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Font color based on value in Data Repeater

40 views
Skip to first unread message

Micah

unread,
Jul 8, 2002, 6:44:27 PM7/8/02
to
ASP.NET/VB.NET

I'm using a Data Repeater. I need to change font color based on the
value of a date field in the <itemtemplate>. Anyone know how this can
be done?

Micah

VBDotNet Team [MS]

unread,
Jul 12, 2002, 5:07:26 PM7/12/02
to
You can do something like this:

In your ASP/HTML code add

<ITEMTEMPLATE>
<ASP:TABLE id="tblData" runat="server">
<ASP:TABLEROW>
<ASP:TABLECELL FontColor='<%# FormatDate(DataBinder.Eval(Container,
"DataItem.DateColumn")) %>'>
<%# FormatDate(DataBinder.Eval(Container,
"DataItem.DateColumn")) %>
</ASP:TABLECELL>
</ASP:TABLEROW>
</ASP:TABLE>
</ITEMTEMPLATE>

where 'DateColumn' is the name of the column which holds your date value.

Then in your code behind file create a function that will return the color
you want based on the date:

Protected Function FormatDate(ByVal dteDate As Date) As
System.Drawing.Color
Dim c As System.Drawing.Color
If <PERFORM COMPARISON HERE> Then
Return c.AntiqueWhite <SELECT YOUR COLOR>
Else
Return c.White <SELECT YOUR COLOR>
End If
End Function


Obviously this code needs a little cleanup, but it should get you started in
the right direction.

Patrick Baker
VB .NET


--
This posting is provided "AS IS" with no warranties, and confers no rights.

"Micah" <micahb...@yahoo.com> wrote in message
news:a9c6259b.02070...@posting.google.com...

0 new messages