在代码隐藏中使用 vb.net 在表中隐藏 tr 或 td

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21214351/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:28:59  来源:igfitidea点击:

Hide tr or td in a table using vb.net in codebehind

asp.netvb.net

提问by ITTIHAD FC.

In my masterpage I have links for users also the authorization is different like admin and regular user.

在我的主页中,我有用户链接,授权也不同,如管理员和普通用户。

links under each other and I can hide the hyperlinks depending on authorization status but the problem is i.e when I have 3 links the second link for the admin the link will hide when the user is regular and the link place empty like 123 1 3.

链接相互关联,我可以根据授权状态隐藏超链接,但问题是当我有 3 个链接时,管理员的第二个链接将隐藏当用户是常规链接并且链接位置为空时,如 123 1 3。

So I have an idea using table each link in one tr but I can`t hide td or tr because Visible is not in properties.

所以我有一个想法在一个 tr 中使用 table 每个链接,但我不能隐藏 td 或 tr 因为 Visible 不在属性中。

any help? thank you

有什么帮助吗?谢谢你

回答by Vignesh Kumar A

According to how to hide a having asp.net control:

根据如何隐藏具有 asp.net 控件

you can give ID either to the TD or TR to which you want to hide/show with the runat="server" and also you can take that tr/td inside the div tag and give id to that div tag and also runat=server attribute and after that you can pro grammatically hide/show that div.

like

<pre>

<tr id="trhide" runat="server"> </tr>

</pre> 

in code behind write

trhide.visible=true/false

您可以将 ID 指定给要使用 runat="server" 隐藏/显示的 TD 或 TR,也可以将该 tr/td 放入 div 标签中,并将 id 指定给该 div 标签以及 runat=server属性之后,您可以在语法上隐藏/显示该 div。

喜欢

<pre>

<tr id="trhide" runat="server"> </tr>

</pre> 

在后面写的代码中

trhide.visible=true/false

回答by user7222005

In the master page VB code behind add a public procedure: Then call the public set from your aspx page.

在母版页 VB 代码后面添加一个公共程序:然后从您的 aspx 页面调用公共集。

'======================================================================================================
    'Set Tab No invisible
    '======================================================================================================
    Public Sub setTabNumberLabel(visible As Int16)
        If visible = 0 Then
            td_page.Visible = False
        Else
            td_page.Visible = True
        End If
    End Sub

The master aspx would be:

主 aspx 将是:

   <table style="width:100%">
        <!--<tr style="background-color:#565656;">-->
        <tr>
            <td style="width:15%;text-align:left;vertical-align:bottom;padding-left:20px;">Stategic Energy Assessment ( <asp:Label ID="lbl_year_ended" runat="server" /> )</td>
            <td style="text-align:center;vertical-align:bottom;"><asp:Label ID="lbl_utility_name_and_id" runat="server" /></td>
            <td id="td_page" runat="server" style="width:15%;text-align:right;vertical-align:bottom;padding-right:20px;">Tab No:&nbsp;<asp:Label ID="lbl_page" runat="server" /></td>
        </tr>
        <tr><td colspan="3" style="vertical-align:central"><hr /></td></tr>
        <tr>
            <td style="width:15%;text-align:left;vertical-align:central">
                <asp:Label ID="lbl_print_version" runat="server" Text="View Printable Vision" Visible="false" />
            </td>
            <td style="font-size:larger; font-weight:bold; text-align:center; text-transform:capitalize;vertical-align:central">
                <asp:Label ID="lbl_schedule_name" runat="server" />
            </td>
            <td style="width:15%;text-align:right;vertical-align:central;padding-right:20px;">
                <asp:LinkButton ID="btn_footnotes" runat="server" Visible="false">Footnotes</asp:LinkButton>
                &nbsp;
                </td>
            </tr>
        <%--<tr><td colspan="3" style="vertical-align:central" class="auto-style1"></td></tr>--%>
        <tr><td colspan="3" style="vertical-align:central; padding-right:20%;padding-left:20%; ">
            <i><asp:Label ID="lbl_headnotes" runat="server" Text="" /></i></td></tr>
        <tr><td colspan="3" style="vertical-align:central"><hr /></td></tr>
    </table>

回答by Sangram Nandkhile

The other answer is correct and works fine. Just adding complete piece of code.

另一个答案是正确的并且工作正常。只需添加完整的代码。

It's quite amusing that you don't need to add runat=serverfor a table but you can still hide tr for that table using runat attribute.

很有趣的是,您不需要runat=server为表添加,但您仍然可以使用 runat 属性隐藏该表的 tr。

<table>
<tr>
    <td>aa</td><td>bb</td>
</tr>
<tr id="trHide1" runat="server">
    <td>aa</td><td>bb</td>
</tr>
<tr id="trHide2" runat="server">
    <td>aa</td><td>bb</td>
</tr>
<tr>
    <td>aa</td><td>bb</td>
</tr>
</table>

Now just set properties in codebehind (hiding the tr)

现在只需在代码隐藏中设置属性(隐藏 tr)

 trHide1.Visible = false;
 trHide2.Visible = false;