Conditional Colors in a DataList Control

J

Jerry Camel

One of the fields in my datalist is an expiration time. How can I make that
time show in red if it is less than one hour away? Thanks.

Jerry
 
G

Guest

Jerry
One way is to wire the ItemDataBound event of your datalist
Inside the method (in C#

DataRowView drv = (DataRowView) e.Item.DataItem
if(drv == null) return
if(drv[<ColumnName or Index Value>].ToString() == "<your criteria>") //Implement your own logic here depending on your dat
e.Item.BackColor = System.Drawing.Color.Red; //I used backcolor but it also has a CssClass property you can set

HTH
Suresh

----- Jerry Camel wrote: ----

One of the fields in my datalist is an expiration time. How can I make tha
time show in red if it is less than one hour away? Thanks

Jerr
 
G

Guest

Another way is to use a helper function

In your codebehind put this funciton

protected string GetMyValInColor(object myobj

if(myobj.ToString() == "xyz") // use your time evaluation her
return "<FONT color=\"#ff0000\">" + myobj.ToString() + "</FONT>"

return myobj.ToString()


Then in your aspx page

<ItemTemplate><%# GetMyValInColor(DataBinder.Eval(Container.DataItem, "<dataitemname>")) %></ItemTemplate

This method is less costlier than the one I gave before

Suresh

----- Suresh wrote: ----

Jerry
One way is to wire the ItemDataBound event of your datalist
Inside the method (in C#

DataRowView drv = (DataRowView) e.Item.DataItem
if(drv == null) return
if(drv[<ColumnName or Index Value>].ToString() == "<your criteria>") //Implement your own logic here depending on your dat
e.Item.BackColor = System.Drawing.Color.Red; //I used backcolor but it also has a CssClass property you can set

HTH
Suresh

----- Jerry Camel wrote: ----

One of the fields in my datalist is an expiration time. How can I make tha
time show in red if it is less than one hour away? Thanks

Jerr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top