在gridview 列表中,需要添加如下效果,如果經(jīng)過時變色,移開時還原成以前的顏色,行選中時通過加深色,從而知道選中了哪行
在gridview 列表中,需要添加如下效果,如果經(jīng)過時變色,移開時還原成以前的顏色,行選中時通過加深色,從而知道選中了哪行,特別是列表數(shù)據(jù)比較多的時候,標志很重要,同時觸發(fā)選中行事件,那么如何 行選中加顏色,同時也出發(fā)我們事件了?如果我們通入 e.row.attributes.add(onclick, 綁定兩次,發(fā)現(xiàn)只能觸發(fā)其中的一個,其實可以把另個放到一個里面
下面是具體的例子:
代碼如下:
protected void editgridview_rowdatabound(object sender, gridviewroweventargs e)
{
if (e.row.rowtype== datacontrolrowtype.datarow)
{
//當鼠標放上去的時候 先保存當前行的背景顏色 并給附一顏色
e.row.attributes.add(onmouseover, currentcolor=this.style.backgroundcolor;this.style.backgroundcolor='inactivecaptiontext',this.style.fontweight
='';this.style.cursor='hand';);
//當鼠標離開的時候 將背景顏色還原的以前的顏色
e.row.attributes.add(onmouseout, this.style.backgroundcolor=currentcolor,this.style.fontweight='';);
//當鼠標單擊時,加深色標志
e.row.attributes.add(onclick, setvalue();if(window.oldtr!=null){window.oldtr.runtimestyle.csstext='';}this.runtimestyle.csstext='background-color:#e6c5fc';window.oldtr=this);
}
}
js代碼:
代碼如下:
<script type=text/javascript >
function setvalue() {
alert('行單擊事件,同時變色');
}
</script>
更多信息請查看IT技術專欄