Conditional Colors in a DataList Control

  • Thread starter Thread starter Jerry Camel
  • Start date Start date
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
 
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
 
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
 
Back
Top