473,324 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

getting at cell in gridview

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 ***
May 31 '06 #1
2 1120
"Mike P" <mi*******@gmail.com> wrote in message
news:OV**************@TK2MSFTNGP04.phx.gbl...
Is this possible?


What happened when you tried it...? :-)
May 31 '06 #2
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" <mi*******@gmail.com> wrote in message
news:OV**************@TK2MSFTNGP04.phx.gbl...
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 ***

May 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Neil | last post by:
I have a gridview which is being populated with no problems. I want to be able to reference the data from the cells in the row but having followed an example on MSDN cannot get any data to be...
1
by: Jon S via DotNetMonster.com | last post by:
HI all, I'm returning a dataset to a gridview control. When the gridview asp.net control is populated from the returning dataset some of the cells remain empty. This is expected as some data...
11
by: Jo | last post by:
Hi all, I have a gridview displaying a dataset and some buttons. When a certain cell of this datasetrow is empty, I want a button in that row to be visible, otherwise no button should be shown...
1
by: K B | last post by:
I would like to create a gridview as below: Project Name 1-1 1-2 1-3 1-4 1-5 1-6 Project 1 BLUE BLUE BLUE BLUE GREEN GREEN more projects I would like to fill the...
3
by: Bill Gower | last post by:
I have an cell which contains a field member which is filled with String.Empty. When I retrieve the value in the cell with Cells.Text.ToString() and try to compare it to String.Empty, I can't...
2
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi, I've bind a grdiview to a database and it's working fine. but what I want to do is if the data in certain cell exceed the cell width the that cell will only show the words with some dots...
14
by: Mike | last post by:
I have a gridview that has a button in the last cell of each row. I want to get the text from cell 1 for that row the button was clicked on. So if my gridview looks like this: N-12 BMW ...
3
by: David C | last post by:
I have a GridView and when the SelectedIndexChange occurs I want to put the value of a BoundField into a TextBox (txtPropertyID) on the page. Below is the code I am using but it is not getting the...
4
by: foolmelon | last post by:
Before AJAX, we were able to focus a cell in a gridview during a fullpage postback. After putting the gridview inside an UpdatePanel, we cannot focus a cell in this gridview anymore. Does anybody...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.