Assigning a Nested Panel to not visible=false not working.

Good afternoon, I'm currently working in a control that looks like this:

Datalist1
    Gridview
    Datalist3
        Panel
        Gridview30
        /Panel

Now my ultimate goal is that if some criteria is met, I want to set the Panel.Visible = False.  I have the code working, that will find the Gridview and based on it's criteria set the Panel visible to false... however when the page is rendered it is still set to true.  I know the code to set it to false is working because if I do:

Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
Dim Dl3 As DataList = CType(e.Item.FindControl("Datalist3"), DataList)
        If Dl3.Items.Count <> 0 Then
            Dim gv30 As GridView = CType(FindC("GridView30", DataList1.Controls), GridView)
            Response.Write(gv30.Rows.Count.ToString() & ",")
            If gv30.Rows.Count > 0 Then
                Dim pnl1 As Panel = CType(FindC("pnlDStrut", DataList1.Controls), Panel)
                pnl1.Visible = False
                Response.Write(pnl1.Visible.ToString()) <-------DISPLAYS "False" at the top of the page.----->
            End If
        End If
End Sub
However, the panel is still visible - I'm assuming since it's default property is true - that is somehow overriding what I set it to.  Whatever the default mode is set to, that's how it's rendered on the page when it's done.

(FindC is a function that finds nested control, btw)
ANY ideas at all on how to fix this and have my code be the final say in it?


LVL 8
arhameAsked:
Who is Participating?
 
vb_jonasConnect With a Mentor Commented:
Hi! Perhaps I don't understand your purposes, but since datalist3 is databound, isn't there you should set the panel1=false? To achieve that, and perhaps a more controllable solution - I would create a usercontrol containing datalist3 with panel and gridview30, and code DataList3_ItemDataBound from within the usercontrol.
0
 
planoczCommented:
Have you tried changing from panel visble= false to just using bringtofront or senttoback?
0
 
arhameAuthor Commented:
I believe those are for win forms - I'm doing this in a web application.  Are those usable in a Web Application?

I have tried adding style instead of visible, like pnl1.style.add("display", "none") and that doesn't work either.  I've noticed since that even if I try to set the Gridview's visibility to false, even that doesn't work. It accepts it and puts it in place according to code, but when the page gets rendered it's still there.  There has to be a trick to doing this to nested controls.... it works on the first level of being nested, but not the 2nd....
0
 
arhameAuthor Commented:
vb jonas,

I had tried that before, under Datalist3 - it was giving me an object reference not found reference to the gridviews.  However, I must have been doing something wrong.  At your suggestion I tried it again, and I am actually able to get it working this way.

I tried that almost 2 full days ago, was the first way I tried it.  I have no clue what I was doing wrong at the time, but since it's working now I won't complain.  I think I was trying in my findc function to pass it Datalist3.Controls, isntead of Datalist1.Controls... maybe.  Dunno.  Either way, thanks for pushing me that direction again.
    Protected Sub DataList3_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
        Dim gv30 As GridView = CType(FindC("GridView30", DataList1.Controls), GridView)
        If gv30.Rows.Count = 0 Then
            Dim pnl1 As Panel = CType(FindC("pnlDStrut", DataList1.Controls), Panel)
            pnl1.Visible = False
        End If
        Dim gv7 As GridView = CType(FindC("GridView7", DataList1.Controls), GridView)
        If gv7.Rows.Count = 0 Then
            Dim pnl1 As Panel = CType(FindC("pnlPStrut", DataList1.Controls), Panel)
            pnl1.Visible = False
        End If
        Dim gv8 As GridView = CType(FindC("GridView8", DataList1.Controls), GridView)
        If gv8.Rows.Count = 0 Then
            Dim pnl1 As Panel = CType(FindC("pnlAStrut", DataList1.Controls), Panel)
            pnl1.Visible = False
        End If
    End Sub

Open in new window

0
 
arhameAuthor Commented:
Thanks, I'm going bald too quick as it!  This was driving me crazy!  It made no sense...
0
All Courses

From novice to tech pro — start learning today.