从vb.net代码端隐藏<div> </div>

时间:2010-04-22 21:49:35

标签: html vb.net css-tables

我有这个代码用于在aspx,后端vb.net中隐藏表和单元格。 代码 -

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

现在我使用<div>标签而不是表格。我如何使用类似的代码并使div可见和不可见?

1 个答案:

答案 0 :(得分:10)

runat="server"和ID添加到您的div。然后,您可以使用其Visible属性隐藏div。

标记:

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

VB:

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

您可以使用控件集合循环访问子控件:

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