如何在Asp.net中为gridview的特定行着色 [英] How to color specific row of a gridview in Asp.net

查看:64
本文介绍了如何在Asp.net中为gridview的特定行着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个gridview并将其绑定到数据表.现在基于列值,我要为特定的行着色.请让我知道该怎么做?

谢谢
Mohd Wasif

Hi All,

I have a gridview and bound it datatable .Now on the basis of a column value I want to color specific row .Please let me know how to do it?

Thanks
Mohd Wasif

推荐答案

protected void grdServices_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          {
              if (e.Row.RowType == DataControlRowType.DataRow)
              {
                  if ((string.IsNullOrEmpty(e.Row.Cells[3].Text) != true) || (e.Row.Cells[3].Text != " "))
                  {
                      int result = Convert.ToInt32(e.Row.Cells[4].Text);
                      if (result == 1) e.Row.BackColor = System.Drawing.Color.Aqua;
                      if (result == 2) e.Row.BackColor = System.Drawing.Color.Peru;
                      if (result == 3) e.Row.BackColor = System.Drawing.Color.Azure;
                      if (result == 5) e.Row.BackColor = System.Drawing.Color.BlanchedAlmond;
                      if (result == 6) e.Row.BackColor = System.Drawing.Color.Coral;
                      if (result == 4) e.Row.BackColor = System.Drawing.Color.Cornsilk;
                  }
              }
          }
      }



如果您获得任何帮助,请标记为解决方案".



Mark as Solution if u get any help


您可以在RowDataBound()事件上进行操作.现在,基于列值,您可以更改行背景色

You can do it on RowDataBound() event. Now on the basis on column value you can change row backcolor

e.Row.BackColor = Drawing.Color.Red;


这篇关于如何在Asp.net中为gridview的特定行着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆