开发者

Hiding <div> from vb.net code side

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 HtmlTable开发者_如何学GoCell In row.Cells
                            cell.Visible = (cell.ID = "b1")
                        Next
                    Else
                        row.Visible = False
                    End If
                Next

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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜