conditional grid formatting based on non-visible column

Discussion in 'ASP .Net' started by Keith G Hicks, Apr 8, 2008.

  1. I have a gridview (asp.net 2.0) where I'm trying to format rows based on a
    NON VISIBLE column. It doesn't seem to work. When column 0 below is visible,
    the row is formatted as expected but when it's not, it doesn't do anything.
    How can I do this so that the formatting is based on the value of a
    non-visible column?

    If e.Row.RowType = DataControlRowType.DataRow Then
    If e.Row.Cells(0).Text = "1" Then
    e.Row.Font.Bold = True
    e.Row.Font.Italic = True
    e.Row.ForeColor = Drawing.Color.DarkBlue
    e.Row.Cells(1).Text = "   " & e.Row.Cells(1).Text
    End If
    End If

    Thanks,

    Keith
    Keith G Hicks, Apr 8, 2008
    #1
    1. Advertising

  2. Are you doing this on postback? Non-visible controls don't come back in
    postbacks. A good place for non-visible values is DataKeys collection.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Keith G Hicks" <> wrote in message
    news:...
    >I have a gridview (asp.net 2.0) where I'm trying to format rows based on a
    > NON VISIBLE column. It doesn't seem to work. When column 0 below is
    > visible,
    > the row is formatted as expected but when it's not, it doesn't do
    > anything.
    > How can I do this so that the formatting is based on the value of a
    > non-visible column?
    >
    > If e.Row.RowType = DataControlRowType.DataRow Then
    > If e.Row.Cells(0).Text = "1" Then
    > e.Row.Font.Bold = True
    > e.Row.Font.Italic = True
    > e.Row.ForeColor = Drawing.Color.DarkBlue
    > e.Row.Cells(1).Text = "&nbsp;&nbsp;&nbsp;" & e.Row.Cells(1).Text
    > End If
    > End If
    >
    > Thanks,
    >
    > Keith
    >
    >
    Eliyahu Goldin, Apr 8, 2008
    #2
    1. Advertising

  3. Keith G Hicks

    Guest

    It looks like he's doing it on the RowDataBound. If that's the case,
    and the hidden column is the problem, you could wait until the Page's
    PreRender event to hide the column.
    , Apr 8, 2008
    #3
  4. Interestingly I tried that last night. I tried making the column visible in
    the design and then hiding the column in other events including the
    PreRender one. That didn't work either. I am not sure which event fires
    after ALL of the grid's rows have been handled in the RowDataBind event
    (which is where, as you surmised, I'm running my other code).

    <> wrote in message
    news:...
    > It looks like he's doing it on the RowDataBound. If that's the case,
    > and the hidden column is the problem, you could wait until the Page's
    > PreRender event to hide the column.
    >
    Keith G Hicks, Apr 8, 2008
    #4
  5. Keith G Hicks

    Guest

    Hmm.. that worked for me. I tested your scenario. You're right, it
    doesn't work when the column is hidden. So I made it visible on the
    client side, and hid the column like so on the server side:

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.PreRender
    Me.grd.Columns(1).Visible = False
    End Sub

    In this case, the grid was formatted correctly. You have to make sure
    the formatting happens before hiding the column. So, if you're
    formatting in RowDataBound you can hide the column in PreRender. You
    can verify this yourself by putting stops on each of the events.
    (Click in the gray to the left of the line number.)

    Try it again. Make sure you close your debugger instance before
    verifying. I don't know how many times I've been trying to figure
    something out and simply closing the browser window and re-opening it
    helped.
    , Apr 8, 2008
    #5
  6. OK. Thanks for the info. I'll test your suggestion. I'm sure it will work
    fine.

    Keith

    <> wrote in message
    news:...
    > Hmm.. that worked for me. I tested your scenario. You're right, it
    > doesn't work when the column is hidden. So I made it visible on the
    > client side, and hid the column like so on the server side:
    >
    > Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.PreRender
    > Me.grd.Columns(1).Visible = False
    > End Sub
    >
    > In this case, the grid was formatted correctly. You have to make sure
    > the formatting happens before hiding the column. So, if you're
    > formatting in RowDataBound you can hide the column in PreRender. You
    > can verify this yourself by putting stops on each of the events.
    > (Click in the gray to the left of the line number.)
    >
    > Try it again. Make sure you close your debugger instance before
    > verifying. I don't know how many times I've been trying to figure
    > something out and simply closing the browser window and re-opening it
    > helped.
    Keith G Hicks, Apr 8, 2008
    #6
    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. spamfurnace
    Replies:
    1
    Views:
    2,632
    Scott M.
    May 24, 2004
  2. Brian Henry

    data grid conditional row formatting

    Brian Henry, Jul 8, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,084
    Brian Henry
    Jul 8, 2004
  3. tshad

    button visible/not visible

    tshad, Oct 26, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,444
    Brian Hoops
    Oct 28, 2004
  4. =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?=

    How to transfer a value from an Invisible Grid to an visible Grid

    =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?=, Oct 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    465
    =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?=
    Oct 17, 2005
  5. Keithb
    Replies:
    2
    Views:
    1,133
Loading...

Share This Page