conditional grid formatting based on non-visible column

K

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
 
P

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.
 
K

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).
 
P

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.
 
K

Keith G Hicks

OK. Thanks for the info. I'll test your suggestion. I'm sure it will work
fine.

Keith
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top