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
Solved

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

Posted on 2011-02-15
8
409 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
8 Comments
 
LVL 9

Accepted Solution

by:
gdupadhyay earned 334 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 334 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 16

Assisted Solution

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

Assisted Solution

by:gdupadhyay
gdupadhyay earned 334 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 334 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:agarwalrahul
agarwalrahul earned 83 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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