为了客户要求,GridView前面10行数据显示背景色,实现方法,在GridView数据控件写一个OnRowCreated事件,
<asp:GridView ID="GridView1" runat="server" OnRowCreated="GridView1_RowCreated">
在.aspx.cs写:
View Code 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");
}
}
}