比如Datagrid有一列字段,字段名为Data,这一列的数据全是数字,
我想要达到的效果是:
在这一列中凡是大于0的数据的字体颜色用蓝色显示,等于0的数据的字体用灰色显示,小于0的数据的字体用红色显示
请问要达到这样的效果,代码应该怎么写?

解决方案 »

  1.   

    <asp:TemplateField HeaderText="XXX" >
    <ItemTemplate >
                <%#Convert.ToInt32(DataBinder.Eval(Container.DataItem,"你的数值字段").ToString()) >300?"<font color=red>DataBinder.Eval(Container.DataItem,"你的数值字段")</font>":DataBinder.Eval(Container.DataItem,"你的数值字段")%></...
    </...
      

  2.   

    笨办法:调用后台方法。
    <asp:TemplateField HeaderText="XXX" >
     <ItemTemplate >
       <%# getColorValue(DataBinder.Eval(Container.DataItem,"你的数值字段").ToString())#%>
    public string getColorValue(string mVal)
    {
       如果mVal大于多少,返回字符串 "<font color=red>mVal数值</font>"