Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-02-15
8
Medium Priority
?
413 Views
Last Modified: 2012-05-11
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
Comment
Question by:mawingho
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 9

Accepted Solution

by:
gdupadhyay earned 1336 total points
ID: 34903208
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
 
LVL 9

Assisted Solution

by:gdupadhyay
gdupadhyay earned 1336 total points
ID: 34903213
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
 

Author Comment

by:mawingho
ID: 34903343
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.

 
LVL 16

Assisted Solution

by:Kalpesh Chhatrala
Kalpesh Chhatrala earned 332 total points
ID: 34903558
0
 
LVL 9

Assisted Solution

by:gdupadhyay
gdupadhyay earned 1336 total points
ID: 34903568
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
 
LVL 9

Assisted Solution

by:gdupadhyay
gdupadhyay earned 1336 total points
ID: 34903576
Yes, we can use the CSS style sheet.
But in your case, I believe above option is good.
0
 
LVL 13

Assisted Solution

by:Rahul Agarwal
Rahul Agarwal earned 332 total points
ID: 34903638
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
 

Author Closing Comment

by:mawingho
ID: 34903675
thanks
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question