• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

tgbaoli

好记性不如烂笔头
  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

设置GridView行的背景色以及鼠标经过时背景色变换

做个根据时间变化比较而用颜色表示的GridView,主要是通过RowDataBound事件来操作:

 

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    
{
        
if (e.Row.RowType == DataControlRowType.DataRow)//判断是否是DataRow,以防止鼠标经过Header是也有效果
        {
            
            
int tempdate = Convert.ToInt16(DataBinder.Eval(e.Row.DataItem, "DayCount"));//获取时间比较的结果值

            
if (tempdate > 20 && tempdate < 841)
            
{
                
//设置背景色
                e.Row.BackColor = Color.Red
                  
//鼠标经过时,背景色变换
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#CDCD00';this.style.color='#884';this.style.cursor='#884'");
                e.Row.Attributes.Add(
"onmouseout", "this.style.backgroundColor='Red';this.style.color='black';this.style.cursor='blue'");

            }

            
else if (tempdate > 841)
            
{
                e.Row.BackColor 
= Color.Turquoise;
                e.Row.Attributes.Add(
"onmouseover", "this.style.backgroundColor='#CDCD00';this.style.color='#884';this.style.cursor='#884'");
                e.Row.Attributes.Add(
"onmouseout", "this.style.backgroundColor='Turquoise';this.style.color='black';this.style.cursor='blue'");
            }

            
else
            
{
                e.Row.BackColor 
= Color.White;
            }

         }

     }

    

 

posted on 2008-07-29 15:11  铁山  阅读(636)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3