加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – .Net Gridview在鼠标悬停后恢复交替颜色

发布时间:2020-12-16 01:40:08 所属栏目:百科 来源:网络整理
导读:我有一个gridview与alternatingRowStyle属性设置. asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" OnRowDataBound="GridView1_RowDataBound" onselectedindexchanged="GridView1_SelectedIndexChan
我有一个gridview与alternatingRowStyle属性设置.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="SqlDataSource2" OnRowDataBound="GridView1_RowDataBound"
        onselectedindexchanged="GridView1_SelectedIndexChanged" AlternatingRowStyle-BackColor="#f0f1f3">

我还想在光标移动时突出显示行:

protected void GridView1_RowDataBound(object sender,GridViewRowEventArgs e)  
{  
        if (e.Row.RowType == DataControlRowType.DataRow)  
        {  
            e.Row.Attributes.Add("onmouSEOver","this.style.backgroundColor='#ceedfc'");  
            e.Row.Attributes.Add("onmouSEOut","this.style.backgroundColor=''");  
            e.Row.Attributes.Add("style","cursor:pointer;");

我遇到的问题是,当鼠标移过该行时,它将恢复为白色,而不是之前的颜色,这在一半的行中是不同的.我想我可以在为每个“onmouSEOve”事件替换它之前保存当前的rowcolor,但是如果快速鼠标移动可能会搞砸了,这似乎很昂贵且令人担忧.

我没有看到gridview行的属性告诉我它是否是备用行但是rowindex上的简单奇数/偶数确定最好在这里?

有更好的建议吗?

谢谢.

-担

解决方法

存储原始样式.然后将样式backgroundColor设置为this.originalstyle.

protected void GridView1_RowDataBound(object sender,"this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#ceedfc'");  
            e.Row.Attributes.Add("onmouSEOut","this.style.backgroundColor=this.originalstyle");  
            e.Row.Attributes.Add("style","cursor:pointer;");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读