有一gridview,如何比較兩列的值,如果後一列的值大於前一列的,則為紅色顯示,謝謝

解决方案 »

  1.   

    两列应该绑定在不同的字段a,b,用一个方法来实现判断:
    <%# DataBinder.Eval(Container.DataItem,"a")%>&nbsp;<%# Compare(DataBinder.Eval(Container.DataItem,"a").ToString(),
    DataBinder.Eval(Container.DataItem,"b").ToString())%>
    public string Compare(string a,string b)
    {
    string str;
       if (b>a)
       {
              str="<font color='red'>"+b+"</font>";
        }
       else
        {
              str=b;
         }
        return str;
    }
      

  2.   

    GridView1_RowDataBound可以嗎?可是我不太會用gridviewrow
      

  3.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
            {
                DataRowView mydrv = ds.Tables[0].DefaultView[i];
                int prod = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "一周實際生產能力"));
                int order = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "一周業務接單量"));
                    if (order < prod)
                        // e.Row.BackColor = System.Drawing.Color.Yellow;
                        GridView1.Rows[i].Cells[3].BackColor = System.Drawing.Color.Red;
            }       
        }
    好像不行