conditional grid formatting based on non-visible column
conditional grid formatting based on non-visible column
am 08.04.2008 05:35:21 von Keith G Hicks
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
Re: conditional grid formatting based on non-visible column
am 08.04.2008 12:09:13 von Eliyahu Goldin
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:ukQl9lSmIHA.4712@TK2MSFTNGP04.phx.gbl...
>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
>
>
Re: conditional grid formatting based on non-visible column
am 08.04.2008 15:19:36 von PopeDarren
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.
Re: conditional grid formatting based on non-visible column
am 08.04.2008 16:00:16 von Keith G Hicks
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:60c5bcc4-aee7-481a-9e2a-45a592d3171e@u3g2000hsc.googleg roups.com...
> 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.
>
Re: conditional grid formatting based on non-visible column
am 08.04.2008 16:51:02 von PopeDarren
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.
Re: conditional grid formatting based on non-visible column
am 08.04.2008 17:28:42 von Keith G Hicks
OK. Thanks for the info. I'll test your suggestion. I'm sure it will work
fine.
Keith
wrote in message
news:e6df7588-21d2-4acb-8a34-c3ce93f065cf@e39g2000hsf.google groups.com...
> 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.