Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > conditional grid formatting based on non-visible column

Reply
Thread Tools

conditional grid formatting based on non-visible column

 
 
Keith G Hicks
Guest
Posts: n/a
 
      04-08-2008
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


 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      04-08-2008
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>
>



 
Reply With Quote
 
 
 
 
PopeDarren@gmail.com
Guest
Posts: n/a
 
      04-08-2008
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.

 
Reply With Quote
 
Keith G Hicks
Guest
Posts: n/a
 
      04-08-2008
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).

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
PopeDarren@gmail.com
Guest
Posts: n/a
 
      04-08-2008
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.
 
Reply With Quote
 
Keith G Hicks
Guest
Posts: n/a
 
      04-08-2008
OK. Thanks for the info. I'll test your suggestion. I'm sure it will work
fine.

Keith

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bind a dropdown in a column in a datagrid based on the dropdown value selected in another column of the datagrid. vishnu ASP .Net 1 03-25-2006 01:24 PM
? ELSE Conditional Comment / Using Conditional Comments Inside Other Tags To Comment Out Attributes Alec S. HTML 10 04-16-2005 02:21 AM
data grid conditional row formatting Brian Henry ASP .Net 2 07-08-2004 04:10 PM
Conditional Row in Grid DC ASP .Net 1 12-23-2003 04:15 PM
how to Add different controls(textBox,DropDownList or some ) in the same column,based upon the value in the previous column (Say second Colum which contain dropdown with some values) ? Balaji ASP .Net Datagrid Control 0 07-07-2003 08:32 AM



Advertisments