如何在鼠标停留在GridView的某行时改变其颜色?在GridView的OnRowDataBound事件中添加如下的代码
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='Aqua'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
如何为GridView的Delete按钮添加删除确定?在GridView的OnRowDataBound事件中添加如下的代码
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')"); // 假设删除按钮在第7行
}
}
}
GridView操作技巧
本文介绍如何在ASP.NET中使用GridView控件实现行高亮显示及添加删除确认功能。通过在GridView的OnRowDataBound事件中添加特定代码,可以实现在鼠标悬停时改变行背景颜色,并为Delete按钮增加删除提示。
1385

被折叠的 条评论
为什么被折叠?



