Nest Gridview Visability

C

Chris

I have a nested gridview. I want the nested gridview to be invisible by
default but to become visible when a button is clicked in its parent. The
code below handles this toggling well when the nested gridview visability
starts at true. When I set it to false the toggle no longer works. I can
some movement on the page and when I step through the code I can see the
visability toggling but the nested gridview remains invisible. It's probably
something stupid but I can't think.

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
GridView1.RowCommand

Dim gv As GridView = DirectCast(sender, GridView)

Dim rowIndex As Integer = e.CommandArgument


Dim childgv As GridView =
DirectCast(gv.Rows(rowIndex).FindControl("gridview2"), GridView)



childgv.Visible = Not childgv.Visible

End Sub
 
E

Eliyahu Goldin

It could be for the reason that server controls with Visible=false don't get
rendered to the client and don't come back on postbacks. When the code runs,
childgv.Visible is always set to what it was on the original page load. If
it was set to true, then
Not childgv.Visible will always return false.

You can hide controls with setting css style display:none.

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

Chris

Thanks, what you are saying about using classes does work but it doesn't
sound right that you can't set a control to be visible if it was set to be
not visible on creation. I am missing the point of what you are saying :)
Regards, Chris.

Eliyahu Goldin said:
It could be for the reason that server controls with Visible=false don't
get rendered to the client and don't come back on postbacks. When the code
runs, childgv.Visible is always set to what it was on the original page
load. If it was set to true, then
Not childgv.Visible will always return false.

You can hide controls with setting css style display:none.

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


Chris said:
I have a nested gridview. I want the nested gridview to be invisible by
default but to become visible when a button is clicked in its parent. The
code below handles this toggling well when the nested gridview visability
starts at true. When I set it to false the toggle no longer works. I can
some movement on the page and when I step through the code I can see the
visability toggling but the nested gridview remains invisible. It's
probably something stupid but I can't think.

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
GridView1.RowCommand

Dim gv As GridView = DirectCast(sender, GridView)

Dim rowIndex As Integer = e.CommandArgument


Dim childgv As GridView =
DirectCast(gv.Rows(rowIndex).FindControl("gridview2"), GridView)



childgv.Visible = Not childgv.Visible

End Sub
 
C

Chris

Oh yes I forgot to add when step through my code I can see the visibility
toggling. My feeling is, may be the childgridview isn't binding for some
reason. Regards, Chris.

Eliyahu Goldin said:
It could be for the reason that server controls with Visible=false don't
get rendered to the client and don't come back on postbacks. When the code
runs, childgv.Visible is always set to what it was on the original page
load. If it was set to true, then
Not childgv.Visible will always return false.

You can hide controls with setting css style display:none.

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


Chris said:
I have a nested gridview. I want the nested gridview to be invisible by
default but to become visible when a button is clicked in its parent. The
code below handles this toggling well when the nested gridview visability
starts at true. When I set it to false the toggle no longer works. I can
some movement on the page and when I step through the code I can see the
visability toggling but the nested gridview remains invisible. It's
probably something stupid but I can't think.

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
GridView1.RowCommand

Dim gv As GridView = DirectCast(sender, GridView)

Dim rowIndex As Integer = e.CommandArgument


Dim childgv As GridView =
DirectCast(gv.Rows(rowIndex).FindControl("gridview2"), GridView)



childgv.Visible = Not childgv.Visible

End Sub
 
E

Eliyahu Goldin

When you step through the code, do you observe Visible=false before running
the statement
childgv.Visible = Not childgv.Visible ?

Consider the following scenario:
1. The page loads first time with childgv.Visible=true.
2. A postback happens. The page reloads, the statement childgv.Visible = Not
childgv.Visible toggles childgv.Visible to false.
3. Since childgv.Visible = false, childgv is not sent to the client.
4. Another postback happens. Since childgv was not sent to the client, it
doesn't come back to server with Visible=false. Instead it is loaded as on
the original page load with Visible = true.
5. The statement childgv.Visible = Not childgv.Visible toggles
childgv.Visible to false again and the client again doesn't get any childgv.

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


Chris said:
Oh yes I forgot to add when step through my code I can see the visibility
toggling. My feeling is, may be the childgridview isn't binding for some
reason. Regards, Chris.

Eliyahu Goldin said:
It could be for the reason that server controls with Visible=false don't
get rendered to the client and don't come back on postbacks. When the
code runs, childgv.Visible is always set to what it was on the original
page load. If it was set to true, then
Not childgv.Visible will always return false.

You can hide controls with setting css style display:none.

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


Chris said:
I have a nested gridview. I want the nested gridview to be invisible by
default but to become visible when a button is clicked in its parent. The
code below handles this toggling well when the nested gridview visability
starts at true. When I set it to false the toggle no longer works. I can
some movement on the page and when I step through the code I can see the
visability toggling but the nested gridview remains invisible. It's
probably something stupid but I can't think.

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
GridView1.RowCommand

Dim gv As GridView = DirectCast(sender, GridView)

Dim rowIndex As Integer = e.CommandArgument


Dim childgv As GridView =
DirectCast(gv.Rows(rowIndex).FindControl("gridview2"), GridView)



childgv.Visible = Not childgv.Visible

End Sub
 

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,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top