主頁 > 知識庫 > Asp.net GridView隔行變色和光棒效果2種方法實現(xiàn)

Asp.net GridView隔行變色和光棒效果2種方法實現(xiàn)

熱門標(biāo)簽:銀行業(yè)務(wù) Mysql連接數(shù)設(shè)置 電子圍欄 團購網(wǎng)站 服務(wù)器配置 科大訊飛語音識別系統(tǒng) Linux服務(wù)器 阿里云
方法一:前臺和后臺配合使用
1.aspx 隔行變色屬性(AlternatingRowStyle BackColor="#f5f5f5" />)
復(fù)制代碼 代碼如下:

asp:GridView ID="gvProjectList" runat="server"
OnRowCreated="gvProjectList_RowCreated">
AlternatingRowStyle BackColor="#f5f5f5" />
/asp:GridView>

1.aspx.cs 后臺事件中設(shè)置鼠標(biāo)至于某行上的變色效果
復(fù)制代碼 代碼如下:

protected void gvProjectList_RowCreated(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#eaeaea';");//這是鼠標(biāo)移到某行時改變某行的背景
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor;");//鼠標(biāo)移走時恢復(fù)
}

方法二:JQuery方式
1.aspx
首先引用 jQuery 函數(shù)庫,在http://jquery.com/ 下載,然后寫css樣式,再加入js代碼。
復(fù)制代碼 代碼如下:

script src="jquery-1.5.2.min.js" type="text/javascript">/script>

復(fù)制代碼 代碼如下:

style type="text/css">
.even {
background:#F5F5F5;
}
.odd {
background:#FFFFFF;
}
.over{
background:#CDE6FF;
}
.tr_chouse {
background:#6AB1FF;
}
/style>

復(fù)制代碼 代碼如下:

script type="text/javascript">
$(document).ready(function(){
$(".gridview tr:odd").addClass("odd"); //奇數(shù)行設(shè)定為 "odd" 樣式
$(".gridview tr:even").addClass("even"); //偶數(shù)行設(shè)定為 "even" 樣式
$(".gridview tr").mouseover(function(){$(this).addClass("over");}) //當(dāng) mouseover 時加入 "over" 樣式
.mouseout(function(){$(this).removeClass("over");}) //當(dāng) mouseout 時移除 "over" 樣式
.click(function(){$(this).toggleClass("tr_chouse");}) //當(dāng) click 加入或移除 "tr_chouse" 樣式,實現(xiàn)數(shù)據(jù)列選取
});
/script>

2013年2月18日 13:57:30更新
復(fù)制代碼 代碼如下:

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>
您可能感興趣的文章:
  • asp.net GridView控件鼠標(biāo)移動某行改變背景顏色(方法一)
  • js實現(xiàn)GridView單選效果自動設(shè)置交替行、選中行、鼠標(biāo)移動行背景色
  • 對GridView的行加顏色并彈出Kindeditor的實現(xiàn)思路

標(biāo)簽:江蘇 衢州 大理 萍鄉(xiāng) 棗莊 蚌埠 衡水 廣元

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Asp.net GridView隔行變色和光棒效果2種方法實現(xiàn)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266