Generate Condition based menu In asp.net.
Generate Condition based menu In asp.net.
Condition based means,some time we have different type user
.
May be 2 or more.so its not practical to show all content
to all user.
For this we develop
condition based menu.its mean show only useful content to user according
to there role.
Here I am using aasp.net Menu Control from toolbox.just
drag it on your web page.aspx`.
<asp:Menu ID ="Menu1" CssClass="menu" runat="server" Orientation="Horizontal"
DynamicSelectedStyle-BackColor="Brown"
DynamicMenuItemStyle-Font-Size="12px"
DynamicMenuItemStyle-Font-Names="Calibri"
DynamicMenuItemStyle-Font-Bold="false"
DynamicMenuItemStyle-ForeColor="#FFFFFF
"
DynamicHoverStyle-ForeColor="#ffffcc"
DynamicMenuItemStyle-VerticalPadding="5px"
StaticMenuItemStyle-Font-Size="14px"
StaticMenuItemStyle-Font-Names="Calibri"
StaticMenuItemStyle-Font-Bold="true"
StaticMenuItemStyle-ForeColor="#575757"
StaticMenuItemStyle-BackColor="#bac2b4"
StaticMenuItemStyle-HorizontalPadding="10px"
StaticHoverStyle-ForeColor="#AA3333"
StaticSelectedStyle-CssClass="menu"
DynamicEnableDefaultPopOutImage="false"
>
<StaticMenuItemStyle
CssClass=""
ItemSpacing="1px"
Height="30px"
/>
<DynamicMenuItemStyle
CssClass=""
BackColor="#575757"
HorizontalPadding="5px"
VerticalPadding="5px"
Width="200px"
/>
<Items>
<asp:MenuItem Text="DashBoard" NavigateUrl="Dashboard.aspx" Value="Home"></asp:MenuItem>
</Items>
</asp:Menu>
Here is menu Control and I just did some style work on it.
Note: In this I am
decleared a menu item in this.
<asp:MenuItem Text="DashBoard" NavigateUrl="Dashboard.aspx" Value="Home"></asp:MenuItem>
Its means this menu item is visible to all user of all type.
Here is our condition part on .cs
page
protected void
Page_Load(object sender, EventArgs e)
{
user_type = "Hr";
if (!Page.IsPostBack)
{
if (user_type == "Hr")
{
MenuItem dms = new
MenuItem("DMS");
//
Document.NavigateUrl = "~/dms.aspx";
dms.Selectable = true;
dms.NavigateUrl = "~/intranet/Employee_KRA/dms.aspx";
Menu1.Items.Add(dms);
///////For menu sub items////
MenuItem f_n_f = new
MenuItem("Forms
& Format");
f_n_f.Selectable = false;
Menu1.Items.Add(f_n_f);
MenuItem u_at = new
MenuItem("Conveyance
Reimbursement Claim");
u_at.NavigateUrl = "~/intranet/Employee_KRA/forms.aspx";
f_n_f.ChildItems.Add(u_at);
MenuItem ineterview = new
MenuItem("InterView
Evaluation");
ineterview.NavigateUrl = "~/intranet/Employee_KRA/interview_enter.aspx";
f_n_f.ChildItems.Add(ineterview);
MenuItem
leave = new MenuItem("Leave Requisition Application");
leave.NavigateUrl = "~/intranet/Employee_KRA/leave_mngmnt.aspx";
f_n_f.ChildItems.Add(leave);
}
else if (user_type ==
"Employee")
{
MenuItem dms = new
MenuItem("DMS");
//
Document.NavigateUrl = "~/dms.aspx";
dms.Selectable = true;
dms.NavigateUrl = "~/intranet/Employee_KRA/dms.aspx";
Menu1.Items.Add(dms);
MenuItem ap_mng = new
MenuItem("Appraisal
Management System");
ap_mng.Selectable = false;
Menu1.Items.Add(ap_mng);
MenuItem k_sub = new
MenuItem("KRA
Submission");
k_sub.NavigateUrl = "~/intranet/Employee_KRA/Employee_KRA.aspx";
ap_mng.ChildItems.Add(k_sub);
MenuItem kra_h = new
MenuItem("KRA
History");
kra_h.NavigateUrl = "~/intranet/LineManager/KRA_LIneManager.aspx";
ap_mng.ChildItems.Add(kra_h);
}
}
Here I am declared two User
1(1) Hr
2(2) Employee
Hr : For HR
user Menu item show 3 main item.
A) DashBoard
b)DMs
c)Form and format
Employee : For Employee user Menu item show 3 main
item.
A)DashBoard
b)DMs
c)Appraisal
Management System
It will look like
this :
Comments
Post a Comment