在事件ItemDataBound中设置。
如下面的就可以,----你自己看了就知道了。
private void dg_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
int Row = this.dg.CurrentPageIndex*this.dg.PageSize + e.Item.ItemIndex ;
if (e.Item.ItemType ==ListItemType.Item || e.Item.ItemType ==ListItemType.AlternatingItem )
{
e.Item.Attributes.Add("onmouseover","this.setAttribute('BKC',this.style.backgroundColor); this.style.cursor='hand';this.style.backgroundColor='Green'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=this.getAttribute('BKC');");
e.Item.Attributes.Add("onmousedown","this.style.cursor='hand';this.style.backgroundColor='red'");
e.Item.Attributes.Add("onmouseup","this.style.backgroundColor=this.getAttribute('BKC');");
e.Item.Attributes["onclick"]="EditDataGrid("+Row.ToString()+");";
}
}
如下面的就可以,----你自己看了就知道了。
private void dg_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
int Row = this.dg.CurrentPageIndex*this.dg.PageSize + e.Item.ItemIndex ;
if (e.Item.ItemType ==ListItemType.Item || e.Item.ItemType ==ListItemType.AlternatingItem )
{
e.Item.Attributes.Add("onmouseover","this.setAttribute('BKC',this.style.backgroundColor); this.style.cursor='hand';this.style.backgroundColor='Green'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=this.getAttribute('BKC');");
e.Item.Attributes.Add("onmousedown","this.style.cursor='hand';this.style.backgroundColor='red'");
e.Item.Attributes.Add("onmouseup","this.style.backgroundColor=this.getAttribute('BKC');");
e.Item.Attributes["onclick"]="EditDataGrid("+Row.ToString()+");";
}
}
Sub DataGrid2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
'---------------------------------------------------
' Add the OnMouseOver and OnMouseOut method a Cell (Column) of DataGrid
'---------------------------------------------------
e.Item.Cells(1).Attributes.Add("onmouseover", "this.style.backgroundColor='#DDEEFF'")
e.Item.Cells(1).Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
e.Item.Cells(2).Attributes.Add("onmouseover", "this.style.backgroundColor='#CC3300'")
e.Item.Cells(2).Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
e.Item.Cells(2).Style("cursor") = "hand"
'---------------------------------------------------
' Change the Mouse Cursor of a particular Cell (Column) of DataGrid
' (Or you may do it for a whole Row of DataGrid :)
'---------------------------------------------------
e.Item.Cells(3).Style("cursor") = "hand"
'---------------------------------------------------
' Add the OnClick Alert MessageBox to a particular Cell (Column) of DataGrid
'---------------------------------------------------
e.Item.Cells(3).Attributes.Add("onclick", "alert('You click at ID: " & e.Item.Cells(0).Text & "!');")
End If
End Sub
Private Sub DeleteDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DeleteDataGrid.ItemDataBound
'对于普通行添加属性
If e.Item.ItemType = ListItemType.Item Then
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#DDEEFF'")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
End If '对于交替行添加属性
If e.Item.ItemType = ListItemType.AlternatingItem Then
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#DDEEFF'")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#EEEEEE'")
End If
End Sub