VS2008下ASP.NET3.5中GridView控件的问题~~~~

来源:百度知道 编辑:UC知道 时间:2024/05/12 04:33:10
以前用过VS2003,现在用的是VS2008.现在正用asp.net3.5作一网站。其中想实现的以功能是,利用GridView空间绑定一数据表,然后当鼠标在该控件上移动时,移动到某一行就变颜色,当鼠标移除时颜色又恢复了。我记得以前在用VS2003的时候开发网站时有一种叫DataGrid的web控件,利用这个控件的ItemDataBound事件就可以实现上面所说的效果,具体代码如:
private void DataGrid_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",
"currentcolor=this.style.backgroundColor,this.style.backgroundColor='#ffff00'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor"); }
}
但是,现在是VS2008了,在做网站时怎么也找不到DataGrid这个web控件了,只有GridView和其差不多,于是就用了。但是要实现效果时确实怎么也找不到ItemDataBound这个事件了,让我困惑了许久。所以在这里想请高手们不吝赐教,帮帮忙~ 谢谢。 如果有哪个可以实现这种“控件的某行随鼠标移动而改变颜色”的事件的话,请写下相应的代码。再次感谢!

GridView的RowDataBound事件,用法如下
-----------------------------------------------------------------
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='#d5f4fe'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}