c# - 根据条件更改 GridView 行颜色

标签 c# asp.net

我想根据某些条件更改 gridview 的特定行颜色。我在 C# 中使用 ASP.NET。

最佳答案

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    e.Row.Attributes.Add("style", "cursor:help;");
    if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState == DataControlRowState.Alternate)
    { 
        if (e.Row.RowType == DataControlRowType.DataRow)
        {                
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#E56E94'");
            e.Row.BackColor = Color.FromName("#E56E94");                
        }           
    }
    else
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='gray'");
            e.Row.BackColor = Color.FromName("gray");                
        }           
    }
}

关于c# - 根据条件更改 GridView 行颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5048762/

相关文章:

c# - 轮播页面指示器

c# - ASP.NET 如何有效地在下拉列表中添加整数

java - TopDesk 概述

javascript - 使用外部js调用aspx.cs函数(单击按钮时)

c# - Entity Framework Core 不从引用表加载相关数据

c# - Windows Phone 8.1 按钮点击参数

c# - 如何捕获在 Entity Framework 4 触发的触发器中调用的 RAISERROR 抛出的 SqlException?

c# - Linq 选择字母之间的范围,例如。 a-e

javascript - ajax POST 调用不同域上的 Web API

asp.net - CSS 问题 : google Chrome not displaying the back groung Image and hence Drop down list not getting displayed properly