簡體   English   中英

根據條件更改Gridview單元格顏色的問題

[英]Issue with changing Gridview cell color depending on condition

如果DOT <今天的日期,我試圖更改gridview的單元格顏色。 我的問題是,即使DOT列>今天的日期,它也會將DOT列的所有行更改為紅色。
在此處輸入圖片說明

這是我的代碼

 protected void OnRowDataBound_gvTest(object sender, GridViewRowEventArgs e)
        {

          if (e.Row.RowType == DataControlRowType.DataRow)
          {

            Label lblDOT = (Label)e.Row.FindControl("DOT");
            DateTime DOTDate = DateTime.Parse(lblDOT.Text);
            if (DOTDate < DateTime.Now)
            {
              //e.Row.BackColor = System.Drawing.Color.Red;
              gvDriverStatus.Columns[3].ItemStyle.ForeColor = System.Drawing.Color.Red;
            }


          }
        }

這個:

gvDriverStatus.Columns[3].ItemStyle.ForeColor = ...

將更改整個列的顏色。 要僅更改單元格顏色,請使用:

e.Row.Cells[3].ForeColor = ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM