May 5, 2011

Change formatting of GridView Row in ASP.Net

protected void gvCH_RowDataBound(object sender, GridViewRowEventArgs e)
 {
 foreach (GridViewRow row in gvCH.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                if (Convert.ToInt32(row.Cells[4].Text.ToString()) > 11)
                {
                    row.Cells[4].BackColor = System.Drawing.Color.LightBlue;
                }

                if (row.Cells[1].Text.ToString() == "Total")
                {
                    row.Cells[1].BackColor = System.Drawing.Color.Plum;
                    row.Cells[2].BackColor = System.Drawing.Color.Plum;
                    row.Cells[3].BackColor = System.Drawing.Color.Plum;

                    row.Cells[1].Font.Bold = true;
                    row.Cells[2].Font.Bold = true;
                    row.Cells[3].Font.Bold = true;
                   
                    row.Cells[1].HorizontalAlign = HorizontalAlign.Center;    

                    row.BorderWidth = 2;   
                }
            }
        }
}

No comments:

Post a Comment