简体   繁体   中英

How to change color of text in rows with DataBinder

I want to change color of text in specific column in each of rows. I have several columns, one of them is named DeliverState which can obtain one of two states - "Delivered" or "NotDelivered"

<td><%# DataBinder.Eval(Container.DataItem, "dbs").ToString()=="1" ? "" : DataBinder.Eval(Container.DataItem, "deliver_state")%></td>

I want to change color of the text (which can be Delivered or NotDelivered) in each row in column DeliverState to green if "Delivered" and red if "NotDelivered" .

What is the best way to do it in .aspx file?

Maybe add a class to the items based on your if condition? that way you can add a styling for eg

.NotDelivered
{ 
  color:Red
}

.Delivered
{
   color:Green
}


<td class="<%#Evaluated your choice : "delivered" : "notDelivered"><...the rest of your statement ..></td>

I would maybe suggest that you put the eval into aa variable that you can call on evaluation of the tenary operator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM