在datagrid上移动鼠标,突出显出移动上的行:
在ItemDataBound事件中
e.Item.Attributes.Add("onmouseover", "setAttribute('attrb', style.backgroundColor); style.backgroundColor = '#f5f5f5' ");
e.Item.Attributes.Add("onmouseout", "style.backgroundColor=getAttribute('attrb');");
点击DATAGRID的行,变色方法
方法一:
后端代码:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <> ListItemType.Footer Then
e.Item.Attributes.Item("onclick") = "DoTrClick(this)"
End If
End Sub
客户端代码:
var lastObj,lastColor;
function DoTrClick(objTr) {
if(lastObj==undefined)
{
lastObj = objTr;
}
lastObj.style.backgroundColor = lastColor;
lastObj = objTr;
lastColor=lastObj.style.backgroundColor;
lastObj.style.backgroundColor = "#CFF3D5"; // 设置选中行背景色
}
方法二:
客户端:
function setItemBackColor(obj)
{
var Curr_TR=document.all.tags("tr");
for(var i=1;i<Curr_TR.length;i++)
{
if (Curr_TR[i].style.backgroundColor =="yellow")
{
Curr_TR[i].style.backgroundColor="white";
}
}
obj.style.backgroundColor="yellow";
}
后台C#代码
private void dgDocClass_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onclick","return setItemBackColor(this)");
}
}