<asp:GridView ID="gvProjectList" runat="server"
OnRowCreated="gvProjectList_RowCreated">
<AlternatingRowStyle BackColor="#f5f5f5" />
</asp:GridView>
1.aspx.cs 后臺事件中設置鼠標至于某行上的變色效果
代碼如下:
protected void gvProjectList_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#eaeaea';");//這是鼠標移到某行時改變某行的背景
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor;");//鼠標移走時恢復
}
方法二:JQuery方式
1.aspx
首先引用 jQuery 函數庫,在http://jquery.com/ 下載,然后寫css樣式,再加入js代碼。
代碼如下:
<script src="jquery-1.5.2.min.js" type="text/javascript"></script>
代碼如下:
<style type="text/css">
.even {
background:#F5F5F5;
}
.odd {
background:#FFFFFF;
}
.over{
background:#CDE6FF;
}
.tr_chouse {
background:#6AB1FF;
}
</style>
代碼如下:
<script type="text/javascript">
$(document).ready(function(){
$(".gridview tr:odd").addClass("odd"); //奇數行設定為 "odd" 樣式
$(".gridview tr:even").addClass("even"); //偶數行設定為 "even" 樣式
$(".gridview tr").mouseover(function(){$(this).addClass("over");}) //當 mouseover 時加入 "over" 樣式
.mouseout(function(){$(this).removeClass("over");}) //當 mouseout 時移除 "over" 樣式
.click(function(){$(this).toggleClass("tr_chouse");}) //當 click 加入或移除 "tr_chouse" 樣式,實現數據列選取
});
</script>
【2013年2月18日 13:57:30更新】
代碼如下:
<script type="text/javascript">
$(function(){ $(".maingrid_text tr:even").addClass("even"); $(".maingrid_text tr:odd").addClass("odd");
$(".maingrid_text tr").hover(function(){$(this).addClass("table_hover")},function(){$(this).removeClass("table_hover")});
});
function EndRequestHandler(){
$(function(){ $(".maingrid_text tr:even").addClass("even"); $(".maingrid_text tr:odd").addClass("odd");
$(".maingrid_text tr").hover(function(){$(this).addClass("table_hover")},function(){$(this).removeClass("table_hover")});
});
}
function reload(){Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);}
$(document).ready(function() { reload(); })
</script>
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com