当鼠标移到DataGrid(2003.net)、GridView(2005.net)行时,改变样式
在Visual Studio 2003.net 的 DataGrid控件ItemDataBound事件里添加如下代码实现:
VS2003.net下实现鼠标移到DataGrid行时,改变样式
private void myDataGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item)
{
e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='#fdf5e6'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='white'");
}
else if(e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='#fdf5e6'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='#EEEEEE'");
}
}
在Visual Studio 2005.net 的 GridView控件RowCreated事件里添加如下代码实现:
VS2005.net下实现鼠标移到GridView行时,改变样式
protected void myGridView_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == (DataControlRowState.Selected | DataControlRowState.Normal) )
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#b1cff8'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white';");
}
}
if (e.Row.RowState == DataControlRowState.Alternate || e.Row.RowState == (DataControlRowState.Selected | DataControlRowState.Alternate))
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#b1cff8'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#fdf5e6';");
}
}
}