(Repaste)GridView的行颜色高亮显示(包括满足条件的行)-Allen Lee
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> 综合其它


(Repaste)GridView的行颜色高亮显示(包括满足条件的行)

发表时间:2012/4/6 22:22:40 评论(0) 浏览(9107)  评论 | 加入收藏 | 复制
   
摘 要:GridView的行颜色高亮显示(包括满足条件的行)
正 文:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //将满足特定条件的行标为高亮
        if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行
        {
            int money = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "MONEY"));//取当前行的列值
            if (money == 77)
                e.Row.BackColor = Color.Red;
            //string customer = (string)DataBinder.Eval(e.Row.DataItem, "CUSTOMER");
            string customer = DataBinder.Eval(e.Row.DataItem, "CUSTOMER").ToString();
            if (customer == "sdf")
                e.Row.BackColor = Color.Red;
        }
        //加入鼠标滑过的高亮效果
        if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行
        {
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='yellow',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';"); 
        }
        //单击行改变行背景颜色
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
           e.Row.Attributes.Add("onclick","this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';");
        }


Access软件网交流QQ群(群号:198465573)
 
 相关文章
(Repaste)gridview的修改,删除,更新,取消操作  【何必见戴  2012/1/18】
【VB.NET小品】TreeView与DataGridView控件...  【煮江品茶  2012/4/4】
【VB.NET小品】TreeView与DataGridView控件...  【煮江品茶  2012/4/4】
【VB.NET小品】TreeView与DataGridView控件...  【煮江品茶  2012/4/4】
(Repaste)ASP.NET 单击和双击事件的 GridVie...  【何必见戴  2012/4/11】
常见问答
技术分类
相关资源
文章搜索
关于作者

Allen Lee

文章分类

文章存档

友情链接