在条件下更改gridview颜色 [英] Change gridview color on condition

查看:80
本文介绍了在条件下更改gridview颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

post removed due to security reasons

post removed due to security reasons

post removed due to security reasons

post removed due to security reasons

post removed due to security reasons





我尝试过:





What I have tried:

Code removed

Code removed

Code removed

Code removed

Code removed

Code removed

Code removed

推荐答案

使用jquery

传递列索引

并使用this.text()获取evry行并比较值在if条件下

并申请.css来改变颜色

https://www.aspsnippets.com/Articles/Dynamically-change-GridView-Row-Background-基于颜色的条件在ASPNet-using-C-and-VBNet.aspx
use jquery
pass the column index
and use this.text() for evry row and compare the value in the if condition
and apply .css to change the color
https://www.aspsnippets.com/Articles/Dynamically-change-GridView-Row-Background-Color-based-on-condition-in-ASPNet-using-C-and-VBNet.aspx


尝试这样的事情:



try something like this:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
          DataRowView drv = e.Row.DataItem as DataRowView;
          if (drv["ostatus"].ToString().ToLower().Equals("accepted"))
          {
              //to change the Row color
              e.Row.BackColor = System.Drawing.Color.Green;

              //to change the Cell color
              e.Row.Cells[8].BackColor = System.Drawing.Color.Green;
          }
     }
}


我使用了TemplateField而不是BoundField解决了我的问题,它可能有助于某人否则我会把代码放在这里。





I've used TemplateField instead of BoundField which resolved my problem, it might help someone else so I will put the codes here.


<asp:TemplateField HeaderText="وضعیت">
    <ItemTemplate>
        <span style="background-color: <%# (Eval("ostatus").ToString() == "Accepted") ? "green;" : (Eval("ostatus").ToString() == "Denied") ? "red;" : "blue;" %>">
            <%# Eval("ostatus") %>
        </span>
    </ItemTemplate>
</asp:TemplateField>


这篇关于在条件下更改gridview颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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