【问题标题】:Hiding/Removing <th> from code behind从后面的代码中隐藏/删除 <th>
【发布时间】:2014-07-18 14:16:25
【问题描述】:

在我的代码中,我正在检索管理员或用户的用户。在我的 aspx 表上,如果用户不是管理员,我想隐藏/删除一个“th”标签。

这是我的html代码:

<table class="table table-striped table-bordered table-hover">
   <thead>
      <tr>
         <asp:Label ID="lblActionHeader" runat="server" Visible = '<%# UserIsAdmin() %>' >
            <th>Action</th>
         </asp:Label>
         <th>Name of Insured</th>
    </tr>
    </thead>
    <tbody>
    <asp:Repeater ID="rptrList" runat="server" OnItemCommand="rptrList_ItemCommand">
       <ItemTemplate>
       <tr>
           <asp:Label ID="lblActionBody" runat="server" Visible = '<%# UserIsAdmin() %>' >
             <td>
               <asp:LinkButton ID="lnkEdit" runat="server" Text="Edit" CommandName="Edit">                      
               </asp:LinkButton>
             </td>
           </asp:Label>
           <td>
              <asp:TextBox ID="lblName" runat="server" Text='<%# Bind("name") %>' Enabled="false" CssClass="m-wrap small"></asp:TextBox>
           </td>
        </tr>
     </ItemTemplate>
    </asp:Repeater>
   </tbody>

</table>

在我的代码中 - 在我的代码后面,我有这个功能可以获取用户是否是管理员。

 public bool UserIsAdmin()
    {
        bool bRet;
        bool.TryParse(Session["isAdmin"].ToString(), out bRet);
        return bRet;
    }

在中继器上它可以工作,但在标题上它不工作。

有没有其他方法可以隐藏标签

【问题讨论】:

标签: html asp.net html-table


【解决方案1】:

我从这个链接得到了答案

Hide Repeater columns based on user privileges

【讨论】:

  • 您应该在提出问题之前写下正确的问题,然后再提出问题,因为它适用于转发器但不适用于标题,这就是为什么我给出了我的页面加载解决方案,但您仍然对此投了反对票
【解决方案2】:

在 page_load 事件中,您需要检查它并使标签可见为 false。

protected void Page_Load(object sender, EventArgs e)
{
       bool bRet;
       bool.TryParse(Session["isAdmin"].ToString(), out bRet);
       lblActionBody.Visible=bRet;
}

【讨论】:

  • 我认为 lblActionBody 应该是 lblActionHeader 因为提问者想要隐藏标题而不是正文。
猜你喜欢
  • 2015-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-15
  • 2011-03-25
  • 2013-03-18
相关资源
最近更新 更多