日期:2014-05-20  浏览次数:20830 次

在GridView1中如何设置随鼠标移动所在行的颜色条?
我原来做一个系统中。显示数据使用的是DataGrid1,
当我的鼠标在DataGrid1移动时,设置了随鼠标移动的颜色条,设置方式:
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover","c=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=c;");
}
}
我现在换了VS2005,改使用控件GridView1,不知如何设置
请大家指点?

------解决方案--------------------
在GridView的RowDataBound中设置:
protected void GVJobs_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;"); 
}
}
------解决方案--------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
}
}

就是这样,刚刚试了试!