• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 414
  • Last Modified:

ASP.NET C# How to change the color of one column in GridView

as per my user's requst, they want one of the column's color to be light blue, how to change that?

Other row and columns are same as default template color....

Hope someone can help!
0
mawingho
Asked:
mawingho
6 Solutions
 
gdupadhyayCommented:
You just need to assign color of all cell for selected column in RowDataBound event;
For example:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
     e.Row.Cells[2].ForeColor = System.Drawing.Color.blue;  // Column 2

}

Open in new window

0
 
gdupadhyayCommented:
One more example:
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].BackColor = System.Drawing.Color.blue; // Column-1
        }
    }

Open in new window

0
 
mawinghoAuthor Commented:
How can I choose some better color?
I need a very ligh blue
like the word "Programming" Zone above.

Is it possible to use Style Sheet?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Kalpesh ChhatralaSoftware ConsultantCommented:
0
 
gdupadhyayCommented:
You can use:

System.Drawing.Color.LightBlue;

Many other color available. Just try by using dot (.) after color. System.Drawing.Color.

Let me know for any question.
0
 
gdupadhyayCommented:
Yes, we can use the CSS style sheet.
But in your case, I believe above option is good.
0
 
Rahul AgarwalTeam LeaderCommented:
Yes, you can by using the below statement in gridview_rowdatabound event.
put your Custom Class Name in Place of bottom-border

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

 If e.Row.RowType = DataControlRowType.DataRow Then
      If previousExpenseType <> e.Row.Cells(2).Text And previousExpenseType.Length > 0 Then
        e.Row.CssClass += "bottom-border"
      End If

      previousExpenseType = e.Row.Cells(2).Text
    End If
0
 
mawinghoAuthor Commented:
thanks
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now