getting at cell in gridview

M

Mike P

I know how to get at different controls in a gridview using FindControl,
and I can change the forecolor or backcolor of the control in the
RowDataBound event (see below). But what I want to do is make reference
to the whole cell and change it's backcolor depending upon the value in
the cell. Is this possible?

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label ForecastType =
(Label)e.Row.FindControl("lblForecastType");

switch (ForecastType.Text)
{
case "Analysis":
ForecastType.BackColor =
System.Drawing.Color.LightBlue;
break;

case "Call Centre":
ForecastType.BackColor =
System.Drawing.Color.Yellow;
break;

case "Data":
ForecastType.BackColor = System.Drawing.Color.Cyan;
break;

case "Data/Analysis":
ForecastType.BackColor =
System.Drawing.Color.LimeGreen;
break;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top