Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > getting at cell in gridview

Reply
Thread Tools

getting at cell in gridview

 
 
Mike P
Guest
Posts: n/a
 
      05-31-2006
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;
}
}



*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      05-31-2006
"Mike P" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> Is this possible?


What happened when you tried it...?


 
Reply With Quote
 
 
 
 
Winista
Guest
Posts: n/a
 
      05-31-2006
This should help. The sample is for formatting row back color. Same concepts
apply for columns too.

http://www.netomatix.com/development...formatrow.aspx

"Mike P" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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;
> }
> }
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= ASP .Net 1 05-09-2006 06:48 PM
How to set and highlight text in JTable cell on selection and/or invoke cell editor directly. news.rcn.com Java 1 07-12-2004 10:22 PM
How do I have a table cell fetch another page to display within the cell? Phillip Roncoroni HTML 14 04-05-2004 05:58 PM
multilink cell phones multilinking shotgun 2 cell phones Calvin Cisco 1 11-07-2003 02:20 PM
moving to cell Y if cell X has value Z. Clarke Rice Computer Support 0 06-30-2003 09:35 AM



Advertisments