Write the below Query in Aspx Design Page
<style type="text/css">
.menustyle
{
background-color:
#6C6C6C;
text-align:
left;
color:
White;
font-family:
Arial;
font-weight:
bold;
font-size: 8pt;
z-index: 20;
}
.mouseover
{
background-color:
#7D7D7D;
text-align:
left;
color:
White;
font-family:
Arial;
font-weight:
bold;
font-size:
8pt;
cursor:
hand;
z-index:
20;
}
</style>
<asp:Menu ID="mnuMaster"
Height="20px"
runat="server"
StaticEnableDefaultPopOutImage="false"
Orientation="Horizontal" Width="85%" OnMenuItemClick="mnuMaster_MenuItemClick">
<StaticMenuStyle CssClass="menustyle" />
<DynamicMenuStyle CssClass="menustyle" />
<StaticMenuItemStyle CssClass="menustyle" />
<DynamicMenuItemStyle CssClass="menustyle" Height="20px" />
<StaticSelectedStyle CssClass="mouseover" />
<StaticHoverStyle CssClass="mouseover" />
<DynamicHoverStyle CssClass="mouseover" />
</asp:Menu>
Then Write the below Query in Aspx.cs Page
//Show The Menu
ht_Authorisedby
= new Hashtable();
ht_AccessTo = new Hashtable();
#region Database
Fetching, Adding in HashTable and Storing in Session
DataTable m_dtUser = new DataTable();
m_dtUser =
BLL.Admin.UserDetails.GetUserType_RefID();
foreach (DataRow dr in
m_dtUser.Rows)
{
strAuthorisedBy
= dr["AuthorisedMenu"].ToString();
strAccessTo
= dr["AccessTo"].ToString();
}
int a = 1; string strKeyVal1 = string.Empty;
foreach (string strsplitAuthorBy in
strAuthorisedBy.Split(','))
{
strKeyVal1
= "KeyAuthorise" + a;
ht_Authorisedby.Add(strKeyVal1,
strsplitAuthorBy.ToString());
a = a + 1;
}
int b = 1; string strKeyVal2 = string.Empty;
foreach (string strsplitAccTo in
strAccessTo.Split(':'))
{
strKeyVal2
= "KeyAccessTo" + b;
ht_AccessTo.Add(strKeyVal2,
strsplitAccTo.ToString());
b = b + 1;
}
#endregion
mnuMaster.Items.Clear();
for (int a = 1; a <= ht_Authorisedby.Count; a++)//each (object obj in ht_Authorisedby.Values)
{
string
strAuthorBy = ((String)ht_Authorisedby["KeyAuthorise" + a]);//(obj));
MenuItem
menuParent = new MenuItem(strAuthorBy); mnuMaster.Items.Add(menuParent);
foreach (string strSubMenuName in
((String)ht_AccessTo["KeyAccessTo" + a]).Split(','))
{
int a1
= strSubMenuName.Split('#').Length;
if
(a1 == 1)
{
MenuItem
menuChild = new MenuItem(strSubMenuName);
menuParent.ChildItems.Add(menuChild);
}
else
{
string[]
strSubChildMenuName = strSubMenuName.Split('#');
MenuItem
menuChild = new MenuItem(strSubChildMenuName[0].ToString());
menuParent.ChildItems.Add(menuChild);
foreach (string strChildSubChildMenuName in strSubChildMenuName[1].ToString().Split(';'))
{
MenuItem
menuSubChild = new MenuItem(strChildSubChildMenuName);
menuChild.ChildItems.Add(menuSubChild);
}
}
}
}
//Assign PageLink
protected void mnuMaster_MenuItemClick(object
sender, MenuEventArgs e)
{
case "MainMenu":
switch (e.Item.Value)
{
case "Sub Menu1":
Response.Redirect("SubMenu1.aspx");
break;
case " Sub Menu2":
Response.Redirect("SubMenu2.aspx ");
break;
case " Sub Menu3":
Response.Redirect("SubMenu3.aspx ");
break;
case " Sub Menu4":
Response.Redirect("SubMenu4.aspx ");
break;
case " Sub Menu5":
Response.Redirect("SubMenu5.aspx ");
break;
}
}
Save The Data in database Given Below The Format
MainMenu# Sub Menu1; Sub Menu2; Sub Menu3; Sub Menu4; Sub Menu5:
using query
if (chkMainMenu.Checked)
{
if
(strAccessTo == "") { strAccessTo
= strAccessTo + " MainMenu #"; }
else {
strAccessTo = strAccessTo + "," + " MainMenu#"; }
if (chkSubMenu1.Checked)
{
if
(tempExpRpt == "") { strAccessTo =
strAccessTo + " Sub Menu1"; }
else {
strAccessTo = strAccessTo + "; Sub Menu1";
}
tempExpRpt
+= " Sub Menu1";
}
if (chkSubMenu2.Checked)
{
if
(tempExpRpt == "") { strAccessTo =
strAccessTo + " Sub Menu2"; }
else {
strAccessTo = strAccessTo + "; Sub Menu2";
}
tempExpRpt += "
Sub Menu2";
}
if (chkSubMenu3.Checked)
{
if
(tempExpRpt == "") { strAccessTo =
strAccessTo + " Sub Menu3"; }
else {
strAccessTo = strAccessTo + "; ";
}
tempExpRpt
+= " Sub Menu3";
}
if (chkSubMenu4.Checked)
{
if
(tempExpRpt == "") { strAccessTo =
strAccessTo + " Sub Menu4"; }
else {
strAccessTo = strAccessTo + "; Sub Menu4";
}
tempExpRpt
+= " Sub Menu4";
}
if (chkSubMenu5.Checked)
{
if
(tempExpRpt == "") { strAccessTo =
strAccessTo + " Sub Menu5"; }
else {
strAccessTo = strAccessTo + "; Sub Menu5";
}
tempExpRpt
+= " Sub Menu5";
}
}