我要判断gridview 第三列的值,如果值等于“2009-01-01” 就把这一行变成黄色,请问怎么取到这个值判断呢?
在线等结贴

解决方案 »

  1.   

    ItemDataBound事件e.Item.Cells[2].Text 。。
      

  2.   

    GridView1_RowDataBound:  for (int i = -1; i < GridView1.Rows.Count; i++)
            {
                string lbl = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "column3"));
                if (lbl == "2009-01-01"
                {
                    e.Row.Cells[2].BackColor= Color.Yellow;
                }
            }
      

  3.   

    using System.Drawing.Imaging;
    using System.Drawing;
      

  4.   

    GridView1_RowDataBound中写入
     protected void gv_result_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType != DataControlRowType.Header && e.Row.RowType != DataControlRowType.Footer)
            {
               if (e.Row.Cells[2].Text.Trim() == "2009-01-01")
               { 
                   e.Row.Cells[2].BackColor= Color.Yellow; 
               } 
           }
    }
      

  5.   

    四楼的哥们错了,RowDataBound事件中并不包含e.Row属性,应该在RowCreated事件中如下
     protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
            {          for (int i = -1; i < GridView1.Rows.Count; i++) 
            { 
                string lbl = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "你要判断的列名")); 
                if (lbl == "2009-01-01" 
                { 
                    e.Row.BackColor= Color.Yellow; 
                } 
            }
            }
    我试过了,绝对正确!