功能描述:
在gridview中,鼠標(biāo)在這個(gè)控件的數(shù)據(jù)列表中移動(dòng)時(shí),該列的背景隨鼠標(biāo)的移動(dòng)而改變背景顏色。
功能實(shí)現(xiàn):
在gridview中新增一個(gè)事件RowDataBound,代碼如下:
復(fù)制代碼代碼如下:
protected void gvwNews_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "color = this.style.backgroundColor;this.style.backgroundColor='#EAFCD5'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=color");
e.Row.Attributes.Add("onclick", "ClickRow()");
}
}
其中的onclick事件是控制選擇行首的復(fù)選框的,點(diǎn)擊行便實(shí)現(xiàn)"點(diǎn)擊"復(fù)選框一樣的效果。代碼如下:
復(fù)制代碼代碼如下:
function ClickRow()
{
var obj = event.srcElement.parentElement.firstChild.firstChild.tagName;
alert(obj);
if(obj!=null && obj.tagName+""!="undefined")
{
obj.checked=obj.checked ? false : true;
}
}
簡(jiǎn)單的幾行代碼所需功能就可以實(shí)現(xiàn)了。