MouseOver上的Gridview行颜色更改 [英] Gridview row color change on MouseOver

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

问题描述

Hello Frnds,



我们的项目基于ASP.NET,Gridview,C#,SqlServer 2005.



我需要更改Mouseover上的行颜色。



已经在我的gridview中使用2列的背景颜色。



和我在行数据绑定事件中编写代码....这是我的代码。



Hello Frnds,

our project is based upon ASP.NET, Gridview, C#, SqlServer 2005.

I need to change the color of row on Mouseover.

already am using background color for 2 columns in my gridview.

and i wrote code in row databound event....this is my code.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {

        e.Row.Attributes.Add("onmouseover",
        "this.originalcolor=this.style.backgroundColor;" + " this.style.backgroundColor='#FDCB0A';");

        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalcolor;");
 
    }
}





这个工作正常,但是当我鼠标悬停时,这个鼠标悬停颜色没有显示在gridview中的那两列(我已经为它们提供了另一种背景颜色)



所以我的要求就是当我鼠标悬停在行上时..那个特别的行包括两列(我已经给出背景颜色)也必须更改鼠标悬停的颜色





请帮助。



提前致谢。



This is working fine, BUT when i mouseover, this mouseover color is not showing on that two columns in gridview(which i have gave another background color to them)

So my requirement is when i mouseover on row.., that particular row INCLUDING that two columns(which i have gave Background color) must also change the color on Mouseover


Please help.

Thanks in advance.

推荐答案

试试以下





Try following


#GridView1 tr.rowHover:hover

   {

       background-color: Yellow;

       font-family: Arial;

   }










<asp:gridview id="GridView1" runat="server" enableviewstate="false" rowstyle-cssclass="rowHover" clientidmode="Static" xmlns:asp="#unknown" />




再添加两个属性,首先删除鼠标上特定单元格的背景颜色悬停然后在鼠标上添加预览背景颜色。然后只有这种父样式才有效。试试这个:

Hi,
Add two more attributes, 1st remove the background color of particular cell on mouse hover and then add the previews background color on mouse out. Then only this parent style will work. Try this:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        // Remove your cell style here
        GridViewRow s = (GridViewRow)e.Row;
        s.Cells[5].Attributes.Add("onmouseover", "oDiv.style.removeProperty('background-color');");
        //Add your cell style here
        s.Cells[5].Attributes.Add("onmouseout", "oDiv.style.background-color=#FFFF");

        e.Row.Attributes.Add("onmouseover",               "this.originalcolor=this.style.backgroundColor;" + " this.style.backgroundColor='#FDCB0A';");
         
        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.originalcolor;");

    }
}







--amit




--amit


阅读这篇文章

http://www.dotnetfunda.com/articles/article1374-how-to-display-mouseover-effect-in-gridview-rows-using-only-css。 aspx [ ^ ]


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

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