getting at cell in gridview

Discussion in 'ASP .Net' started by Mike P, May 31, 2006.

  1. Mike P

    Mike P Guest

    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 ***
     
    Mike P, May 31, 2006
    #1
    1. Advertising

  2. Mike P

    Mark Rae Guest

    "Mike P" <> wrote in message
    news:...

    > Is this possible?


    What happened when you tried it...? :)
     
    Mark Rae, May 31, 2006
    #2
    1. Advertising

  3. Mike P

    Winista Guest

    This should help. The sample is for formatting row back color. Same concepts
    apply for columns too.

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

    "Mike P" <> wrote in message
    news:...
    >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 ***
     
    Winista, May 31, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.rcn.com
    Replies:
    1
    Views:
    9,815
    Chris Smith
    Jul 12, 2004
  2. Phillip Roncoroni
    Replies:
    14
    Views:
    1,143
    Toby A Inkster
    Apr 5, 2004
  3. Empire City
    Replies:
    3
    Views:
    435
    Empire City
    Apr 30, 2004
  4. Thomasa Gregg
    Replies:
    1
    Views:
    180
    Eliyahu Goldin
    Jun 9, 2004
  5. RJ
    Replies:
    1
    Views:
    262
    Eliyahu Goldin
    Feb 17, 2005
Loading...

Share This Page