7

我有这个代码用于隐藏 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 可见和不可见?

4

1 回答 1

11

将 ID添加runat="server"到您的 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
于 2010-04-22T21:55:20.337 回答