标题:转【GridView 和 DataList 内当鼠标移入记录行改变背景颜色问题】
只看楼主
aganarRMJ
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:27
专家分:160
注 册:2009-9-10
结帖率:50%
已结贴  问题点数:20 回复次数:1 
转【GridView 和 DataList 内当鼠标移入记录行改变背景颜色问题】

一、GridView内改变记录行背景色

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        int i;
        //执行循环,保证每条数据都可以更新
        for (i = 0; i < GridView1.Rows.Count; i++)
        {
            //首先判断是否是数据行
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            }
        }
    }

GRIDVIEW里的数据行变色是这么写的

DATALIST里的就简单一些,不用也这么想

二、DataList内改变记录行的背景色

   <asp:DataList runat="server" ID="dlItem" HeaderStyle-BackColor="#8fe45a" ShowHeader="true" GridLines="None" DataKeyField="id" OnItemCommand="dlItem_ItemCommand" OnDataBinding="dlItem_DataBind" OnItemDataBound="dlItem_ItemDataBound">
                <HeaderTemplate>
                 <tr>
                        <td width="35" height="25" align="center" style="background-color:#8fe45a">编号
                      </td>
                        <td width="150" align="center" style="background-color:#8fe45a">国别</td>
                        <td align="center" style="background-color:#8fe45a; width:300px">投资机构</td>
                        <td width="100" align="center" style="background-color:#8fe45a">投资额度</td>
                        <td width="100" align="center" style="background-color:#8fe45a">修改</td>
                    </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr onmouseover="this.style.backgroundColor='#E6F5FA'"   onmouseout="this.style.backgroundColor='' ">
                        <td width="35" height="25" align="center">
                        <%#DataBinder.Eval(Container.DataItem,"id") %>
                      </td>
                        <td width="150" align="center" ><%#DataBinder.Eval(Container.DataItem,"guobie") %></td>
                        <td align="center" ><%#DataBinder.Eval(Container.DataItem,"jigou") %></td>
                        <td width="100" align="center" ><%#DataBinder.Eval(Container.DataItem,"edu") %></td>
                        <td width="100" align="center" ><asp:LinkButton id="btnSelect" Text="删除" CommandName="Delete" runat="server" />&nbsp;|&nbsp;<%--<asp:LinkButton runat="server" ID="chakan" CommandName="select" Text="查看"></asp:LinkButton>--%><asp:HyperLink ID="chakan" runat="server" Text="查看" Target="_blank" NavigateUrl='<%#"../xiangmu.aspx?id="+Eval("id") %>'></asp:HyperLink>&nbsp;|&nbsp;<asp:HyperLink ID="updata" NavigateUrl='<%#"../member.aspx?a=zhaoxm&idu="+Eval("id") %>' runat="server" Text="修改"></asp:HyperLink><%--|<asp:LinkButton runat="server" Text="修改1" OnClick="xiugai_click" ID="xiugai"></asp:LinkButton>--%></td>
                    </tr>
                </ItemTemplate>
                </asp:DataList>
                共有<asp:Label id="lblRecordCount" ForeColor="red" runat="server" />条记录&nbsp;
当前为<asp:Label id="lblCurrentPage" ForeColor="red" runat="server" />/<asp:Label id="lblPageCount" ForeColor="red" runat="server"></asp:Label>页
<asp:LinkButton id="lbnPrevPage" Text="上一页" CommandName="prev" OnCommand="Page_OnClick" runat="server" />
<asp:LinkButton id="lbnNextPage" Text="下一页" CommandName="next" OnCommand="Page_OnClick" runat="server" />
搜索更多相关主题的帖子: 鼠标 DataList GridView 颜色 记录 
2009-09-10 18:08
芙蓉飘雪
Rank: 2
等 级:论坛游民
帖 子:3
专家分:14
注 册:2007-11-4
得分:14 
一般使用第一个,很少用到DataList.
2009-09-10 21:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-285347-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.512185 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved