为了客户要求,GridView前面10行数据显示背景色,实现方法,在GridView数据控件写一个OnRowCreated事件,
<
asp:GridView
ID
="GridView1"
runat
="server"
OnRowCreated
="GridView1_RowCreated"
>
在.aspx.cs写:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
protected
void
GridView1_RowCreated(
object
sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex < 10 ) // 索引从0开始。
{
e.Row.BackColor = Color.Red; // Color.FromName("#FF0000");
}
}
}
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex < 10 ) // 索引从0开始。
{
e.Row.BackColor = Color.Red; // Color.FromName("#FF0000");
}
}
}