【问题标题】:Why background color of gridview cell is not setting?为什么gridview单元格的背景颜色没有设置?
【发布时间】:2016-12-12 16:44:36
【问题描述】:

如果不为空,我将这段代码设置为gridview CELL 的颜色为红色。它做到了,但它为整个列着色,而不是特定的单元格。为什么?

 private void ShowCases()
    {
        short UserID = Convert.ToInt16(Session["UserID"]);

        grdviewCases.DataSource = MngCases.SelectCases(UserID);
        grdviewCases.DataBind();

        foreach (GridViewRow gr in grdviewCases.Rows) 
        {
            if (gr.Cells[14].Text != "")
            {
                gr.Cells[14].BackColor= Color.IndianRed;
            }
        }

    }

简而言之:如果单元格不为空,我想将背景颜色设置为红色,但此代码已绘制第 14 列的所有单元格,均为空且非空。

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

    可能是因为您的“空”单元格实际上包含 

    如果您将代码更改为,

     if (gr.Cells[14].Text != " ")
     {
         gr.Cells[14].BackColor= Color.IndianRed;
     }
    

    它应该工作:

    有时,使用调试器会非常、非常有帮助...:O)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-21
      • 1970-01-01
      • 1970-01-01
      • 2014-04-05
      • 1970-01-01
      • 2019-07-27
      相关资源
      最近更新 更多