【问题标题】:How to highlight the the ASP.net grid row on basis of certain value in columns?如何根据列中的某个值突出显示 ASP.net 网格行?
【发布时间】:2012-02-23 04:05:09
【问题描述】:

我有一个 ASP.net 网格,如果 GRIDview 的一列中有特定值(例如 5),我想更改该行的背景颜色

请帮忙

【问题讨论】:

    标签: asp.net gridview


    【解决方案1】:

    首先您需要订阅OnDataBound-Event。 之后您将e.Row.DataItem 转换为您的自定义对象(或以其他方式检索所需的值。取决于您的数据源类型)

    如果您的条件匹配,您可以通过为e.BackColor 属性分配值来单独设置行的BackColor 属性

    我过去总结过类似here 的东西。 (也许我会在将来的某个时间合并这个响应)

    【讨论】:

      【解决方案2】:

      使用以下代码:

      protected void DrugDetailGridView_RowDataBound(object sender, GridViewRowEventArgs e)
          {
              if (e.Row.RowType == DataControlRowType.DataRow)
              {
                  // To check condition on string value 
                 //Note: "Drug" is my data Column Name  and "Hydralazine" is value to be match
                  if (Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Drug")) == "Hydralazine")
                  {
                      e.Row.BackColor = System.Drawing.Color.Red;
                  }
                  else
                  {
                      // Whatever you want to do.......
                     // e.Row.ForeColor = System.Drawing.Color.Yellow;
                  }
      
                  // To check condition on integer value
                  if (Convert.ToInt16(DataBinder.Eval(e.Row.DataItem, "Dosage")) == 50)
                  {
                      e.Row.BackColor = System.Drawing.Color.Cyan;
                  }
              }
          }
      

      【讨论】:

        猜你喜欢
        • 2021-07-31
        • 2011-12-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-11
        • 2021-08-04
        • 1970-01-01
        • 1970-01-01
        • 2022-10-23
        相关资源
        最近更新 更多