如何在 Asp.net Web 应用程序中更改 gridview 所选项目的背景颜色?
您可以在 GridView 标记下的 aspx 页面中执行此操作:
<SelectedRowStyle BackColor="Orange" />
但是,如果您希望鼠标悬停或鼠标移出时有不同的颜色,请在 RowDataBound 事件下的代码中尝试以下操作
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand';this.style.backgroundColor='orangered'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
}
}
如果您想在不单击按钮的情况下选择一行,另请查看此链接:ASP.NET:在 GridView 中选择一行 http://msmvps.com/blogs/deborahk/archive/2010/01/25/asp-net-selecting-a-row-in-a-gridview.aspx
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)