Solved

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

Posted on 2011-02-15
8
407 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
 
LVL 16

Assisted Solution

by:Kalpesh Chhatrala
Kalpesh Chhatrala earned 83 total points
ID: 34903558
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now