Groups | Blog | Home
all groups > asp.net > february 2006 >

asp.net : GridView Column Color Change


dm1608
2/28/2006 11:30:07 PM
I have a GridView that is using an ObjectDataSource to populate.

One of my columns is named "Status" and can have a value of "Complete",
"Error", "Active", and "Unknown". I would like to have the text for the
word "Error" displayed in RED letters. How can I do this with a GridView
control?


Siva
3/1/2006 12:00:00 AM
Hi,

One of the way to Acheive this you have to use the "RowDataBound Event" you
can check if the text of the cell is "Error" and there you can make the
Color of that text to Red.

//If you know the column index , I assume the column is 3 in this sample
code and applied.
if(e.Row.Cells[3].Text=="Error")

{

e.Row.Cells[3].ForeColor = Color.Red;

}

hope that helps

Regards,

A.Sivakumar.


[quoted text, click to view]

dm1608
3/1/2006 8:01:05 AM
Thanks --

Does anyone know of a way to do this with hardcoding the column #?



[quoted text, click to view]

Hari
3/1/2006 9:08:09 PM
Hi ,
I am a begginer to ASp.Net ,so there should be some easy way for this i am
not sure.

I guess you can use templates for this( i dont have a full code now reg
this) ,
something like this.
SomeList = (Label) e.Item.FindControl("lblsomeID");
assuming a label is kept in that template"
and changing thats templates label color can provide the same result.

Regards,
Hari

AddThis Social Bookmark Button