Click here to Skip to main content
15,067,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Problem Solved
Thank you for all who helped me.

Indu. :)

Hi friends,

I created a Grid View Table (contains MS Access database table).

I have columns

S.No Student Name Student Id DepartmentName
1 Raja 1234 Computer Science
2 Venu 2345 Mechanical
3 Radha 3456 Electronics
4 Ajay 5678 Computer Science

The various departments should filled the backcolor with different colors.

1)Computer Science cell should hightlight the back color with yellow

2) Mechanical as Cyan

3) Electronics as Fuchsia, etc.

I've tried alot to change. But, unable to get.

DepartmentName="Computer Science" change the backcolor to yellow.

I mean i'm able to change the entire column color by putting "ItemStyle-BackColor="Red" , that changes the entire column. But not particular cell with conditions(CSE,Mech,Electronics).

Please guide me for this. Please send me the tutorials links for the above requirement. Thank you.

Updated 24-Mar-10 20:46pm

For having different colors,You need to set the colors dynamically based on the data.
So you just need to you use RowDatabound of the gridview.And in this, you just need to check the data and accordingly can set the color of row/cell.
For sample, have a look to the following link
Formatting the GridView
in RowDatabound event of grid you should be writing this code.
i.e In this event first you should check

protected void grv_RowDataBound(object sender, GridViewRowEventArgs e)
            if (e.Row.RowType == DataControlRowType.Header )
                if (departmentname =="Mechanic")
                    e.Row.Cells[3].Attributes("backgound", "cyan");

HOpe this will work. if there is any problem please let me know.

if (e.Row.RowType == DataControlRowType.Header )
if (e.Row.RowType != DataControlRowType.Header )
try this code in RowDataBound event of grid view.

if (e.Row.Cells[1].Text == "Mechanical ")
                e.Row.Attributes.Add("style", "background-color:Cyan");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900