RowDataBound 事件不生效的有关问题
RowDataBound 事件不生效的问题
数据是手工绑定的,运行之后查看html代码,并没有生效,是不是手工绑定数据的时候这个事件就不能正常生效了,
------解决方案--------------------
还有就是td不能设置背景色
------解决方案--------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//首先判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标停留时更改背景色
string bg=e.Row.BackColor.ToString();
e.Row.Attributes.Add("onmouseover", "this.bgColor='#CED5EC'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.bgColor='" + bg + "'");
}
}
数据是手工绑定的,运行之后查看html代码,并没有生效,是不是手工绑定数据的时候这个事件就不能正常生效了,
------解决方案--------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes["onmouseover"] = "_color=this.bgColor;this.bgColor='#cccccc'";
e.Row.Attributes["onmouseout"] = "this.bgColor=_color";
}
还有就是td不能设置背景色
------解决方案--------------------