Reputation: 195
I have a list view which is used for making a menu in master page and when an user login to master page some list item should be made hidden or set visibility as false. I have attached my list items below. Suggest me some solution.
<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>
I need to hide Oper Master and Employ Master from my list when a particular employee login and those should be visible when admin login into it.
Upvotes: 0
Views: 80
Reputation: 5712
I will give you a start where you can add the rest:
// 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() });
}
Upvotes: 1