Html 从 vb.net 代码端隐藏 <div>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2694783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hiding <div> from vb.net code side
提问by reffe
I have this code for hiding a table and a cell in aspx, backend vb.net. Code -
我有这段代码用于在 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
Now instead of tables I'm using <div>
tags. How can I use similar code and make div's visible and invisible?
现在我使用<div>
标签而不是表格。如何使用类似的代码并使 div 可见和不可见?
回答by AaronSieb
Add runat="server"
and an ID to your div. You can then hide the div using its Visible
property.
runat="server"
向您的 div添加一个 ID。然后,您可以使用其Visible
属性隐藏 div 。
Markup:
标记:
<div ID="myDiv" runat="server">Test DIV</div>
VB:
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