GridView加載時,根據相應條件讓有些內容顯示為紅色在RowDataBind事件中怎麼獲取獲取單元格的值採用e.Row.FindControl("lblLeather_date") as Label 返回null值
採用e.Row.Cells[10].Text 返回""

解决方案 »

  1.   

    if(e.Row.RowType = DataControlRowType.DataRow) 
    {
        if(e.Row.Cells[10].Text.equals("..."))
        {
           //todo
        }
    }
      

  2.   

     for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
            {
                DataRowView mydrv = myds.Tables["table"].DefaultView[i];
                string score = Convert.ToString(mydrv["起薪"]);
                if (Convert.ToDouble(score) < 60)//大家这里根据具体情况设置可能ToInt32等等
                {
                    GridView1.Rows[i].Cells[4].BackColor = System.Drawing.Color.Red;
                }
            }
      

  3.   

      for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
            {
               DataRowView drv = ds.Tables["a"].DefaultView[i];
               string id= Convert.ToString(drv["id"]);
               if (id.Equals(""))
                {
                    GridView1.Rows[i].Cells[4].BackColor = System.Drawing.Color.Red;
               }
            }
      

  4.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
        { 
            if (e.Row.RowType == DataControlRowType.DataRow) 
            { 
                string result = e.Row.Cells[2].Text; 
                int temp; 
                if (int.TryParse(result,out temp)) 
                { 
                    if (Convert.ToInt32(e.Row.Cells[2].Text) < Convert.ToInt32(e.Row.Cells[3].Text))
                    { 
                        e.Row.Cells[2].BackColor = System.Drawing.Color.Red; 
                    } 
                } 
           } 
        }