开发者

asp.net grid color setting

开发者 https://www.devze.com 2023-01-02 23:09 出处:网络
I have a gridview that is bind to the datatable. how to programmaticaly change the co开发者_开发技巧lor of the 1-st column, after the binding has been done?You have to do it while binding is taking pl

I have a gridview that is bind to the datatable. how to programmaticaly change the co开发者_开发技巧lor of the 1-st column, after the binding has been done?


You have to do it while binding is taking place in the RowDataBound Event.

Set the color of the cell in the 1st column in the event:

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


One way to do this is to handle the "OnRowCreated" event. You can do this by adding to this Gridview declaration in the .aspx like this:

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

then you can refer to cells on a row by row basis - this will set the background color of the column to blue.

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

精彩评论

暂无评论...
验证码 换一张
取 消