我有一个列表视图,用于在母版页中制作菜单,当用户登录母版页时,某些列表项应隐藏或将可见性设置为false。我已在下面附上我的清单项目。建议我解决一下。
<div id="cssmenu">
<ul>
<li class="active"><a href="HomePage.aspx"><span>HOME</span></a></li>
<li class="has-sub"><a href="#"><span>MASTER</span></a>
<ul>
<li> <a href="InsDet.aspx"><span>INS MASTER</span></a></li>
<li> <a href="OperDet.aspx"><span>OPER MASTER</span> </a></li>
<li> <a href="EmployDet.aspx"><span>EMPLOY MASTER</span></a></li>
<li class="last"><a href="LoginDet.aspx"><span>LOGIN DETAILS</span></a> </li>
</ul>
</li>
<li><a href="Allot.aspx"><span>NEW CAR</span></a> </li>
<li><a href="Progress.aspx"><span>PROGRESS</span></a></li>
</ul>
</div>
当特定员工登录时,我需要从我的列表中隐藏Oper Master和Employ Master,并且当管理员登录时,这些应该是可见的。
答案 0 :(得分:1)
我会给你一个开始,你可以添加其余的:
// Get employee from Session
Employee employee = (Employee)Session["Employee"];
// Check if employee exists
if(employee != null)
{
RenderMenu(employee);
}
// Method to render list
private void RenderMenu(Employee employee)
{
StringBuilder _menu = new StringBuilder();
_menu.Append("<ul>");
// Property boolean that indicates if the employee is an admin
if(employee.IsAdmin)
{
//Add items for admin
}
_menu.Append("</ul>");
// Panel on the aspx page where you add the menu control
this.pnlMenu.Controls.Add(new LiteralControl() { Text = _menu.ToString() });
}