Solved

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

Posted on 2011-02-15
8
406 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 9

Assisted Solution

by:gdupadhyay
gdupadhyay earned 334 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Asp.net mvc entity issue 6 18
Convert to Hour/minute textbox and compare 3 35
Re-position the objects 7 46
Asp.net mvc 5 5 13
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…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 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

13 Experts available now in Live!

Get 1:1 Help Now