views:

196

answers:

1

i have this code for hiding a table and a cell in aspx, backend vb.net Code -

For Each row As HtmlTableRow In tab_a1.Rows
                    If row.ID = "a1" Then
                        For Each cell As HtmlTableCell In row.Cells
                            cell.Visible = (cell.ID = "a1")
                        Next
                    ElseIf row.ID = "b1" Then
                        For Each cell As HtmlTableCell In row.Cells
                            cell.Visible = (cell.ID = "b1")
                        Next
                    Else
                        row.Visible = False
                    End If
                Next

now instead of tables I'm using tags. How can i use similar code and make div's visible and invisible?

+1  A: 

Add runat="server" and an ID to your div. You can then hide the div using its Visible property.

Markup:

<div ID="myDiv" runat="server">Test DIV</div>

VB:

myDiv.Visible = False 'Hide the div.
myDiv.Visible = True 'Show the div.

You can loop through child controls using the controls collection:

For Each child As Control In myDiv.Controls
    If TypeOf child Is HtmlControl Then
        Dim typedChild As HtmlControl = CType(child, HtmlControl)
        'Search grandchildren, toggle visibility, etc.
    End If
Next
AaronSieb
but i have 50 div's nested in each other so i need to loop through them
reffe
@reffe I've added a description of looping through the Div's child collection.
AaronSieb