2010-06-11 137 views
0

我有一个gridview绑定到数据表。在绑定完成之后如何编程改变第1列的颜色?asp.net网格颜色设置

+0

你是什么意思的“绑定后?”如果它是“绑定之后”,则渲染已完成。 – Keltex 2010-06-11 13:53:47

回答

1

您必须在RowDataBound事件发生绑定时执行此操作。

设置单元格的颜色在事件中的第1列:

protected void gridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    e.Row.Cells[0].BackColor = Color.Red 
} 
1

的一种方式做,这是处理“OnRowCreated”事件。您可以通过在像这样的.aspx加入到这个GridView的声明这样做:

<asp:GridView ID="GridView1" runat="server" OnRowCreated="GridView1_RowCreated" /> 

那么你可以通过行的基础上引用单元格在一行上 - 这将设置列蓝色的背景颜色。

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) 
{ 
    e.Row.Cells[1].BackColor = System.Drawing.Color.Blue; 
}