鼠标悬停GridView的行时相应的行变色,这一脚本这哪个事件中写
鼠标悬停GridView的行时相应的行变色,这一脚本这哪个事件中写
这不用在脚本中写呀,可以在DATAGRID中的ItemDataBound属性中写入:
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='yellow'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=c");
}
用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='#6699ff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
if (e.Row.Cells[7].Controls.Count > 0)
{
((LinkButton)(e.Row.Cells[7].Controls[0])).Attributes.Add("onclick", "return confirm('你确认删除吗?')");
}
}
}