Hi micah,
There is no need to use FormView to display the Admin and staff link.
Use two Panel control and hide the Admin panel if the user is staff.
For checking department i have set the department in session and then from that session value hiding the panel.
Check this example. Now please take its reference and correct your code.
HTML
Login
<asp:Login ID="LoginINNOVATION" runat="server">
<LayoutTemplate>
<table>
<tr>
<td>UserName</td>
<td><asp:TextBox ID="UserName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Password</td>
<td><asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox></td>
</tr>
<tr>
<td>Department</td>
<td>
<asp:DropDownList ID="Department" runat="server" Width="150px">
<asp:ListItem Text="Select" />
<asp:ListItem Text="Admin" />
<asp:ListItem Text="Staff" />
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Button ID="Button1" Text="Login" runat="server" OnClick="ValidateUser" />
</td>
</tr>
</table>
</LayoutTemplate>
</asp:Login>
Default
<div class="left-custom-menu-adp-wrap comment-scrollbar">
<nav class="sidebar-nav left-sidebar-menu-pro">
<ul class="metismenu" id="menu1">
<asp:Panel ID="pnlAdmin" runat="server">
<li>
<a title="Dashboard v.1" href="AdminLanding.aspx">
<i class="fa fa-edit sub-icon-mg" aria-hidden="true"></i>
<span class="mini-sub-pro"><asp:Label ID="Label1ad" runat="server">Enter Admin Page</asp:Label></span>
</a>
</li>
</asp:Panel>
<asp:Panel ID="pnlStaff" runat="server">
<li>
<a title="Dashboard v.1" href="EditExpenses.aspx">
<i class="fa fa-edit sub-icon-mg" aria-hidden="true"></i>
<span class="mini-sub-pro"><asp:Label ID="Label1" runat="server">Enter Staff Page</asp:Label></span>
</a>
</li>
</asp:Panel>
<br />
<asp:LoginName ID="LoginName2" runat="server" />
</ul>
</nav>
</div>
Code
C#
Login
protected void ValidateUser(object sender, EventArgs e)
{
DropDownList ddldepartment = LoginINNOVATION.FindControl("Department") as DropDownList;
string department = ddldepartment.SelectedItem.Text.Trim();
Session["Department"] = department;
// Validate User code.
System.Web.Security.FormsAuthentication.SetAuthCookie(LoginINNOVATION.UserName, LoginINNOVATION.RememberMeSet);
Response.Redirect("~/Default.aspx");
}
Default
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.User.Identity.IsAuthenticated)
{
System.Web.Security.FormsAuthentication.RedirectToLoginPage();
}
else
{
if (Session["Department"] != null && Session["Department"].ToString() == "Staff")
{
pnlAdmin.Visible = false;
}
else if (Session["Department"] != null && Session["Department"].ToString() == "Admin")
{
pnlStaff.Visible = false;
}
}
}
VB.Net
Login
Protected Sub ValidateUser(ByVal sender As Object, ByVal e As EventArgs)
Dim ddldepartment As DropDownList = TryCast(LoginINNOVATION.FindControl("Department"), DropDownList)
Dim department As String = ddldepartment.SelectedItem.Text.Trim()
Session("Department") = department
' Validate User code.
System.Web.Security.FormsAuthentication.SetAuthCookie(LoginINNOVATION.UserName, LoginINNOVATION.RememberMeSet)
Response.Redirect("~/Default.aspx")
End Sub
Default
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.Page.User.Identity.IsAuthenticated Then
System.Web.Security.FormsAuthentication.RedirectToLoginPage()
Else
If Session("Department") IsNot Nothing AndAlso Session("Department").ToString() = "Staff" Then
pnlAdmin.Visible = False
ElseIf Session("Department") IsNot Nothing AndAlso Session("Department").ToString() = "Admin" Then
pnlStaff.Visible = False
End If
End If
End Sub
Screenshot
