// default.aspx //
<style type="text/css">
.ParentMenu
{
font-size: small;
font-family: Tahoma;
font-weight: bold;
padding-left: 6px;
padding-right: 6px;
text-align: center;
background-color: #8B008B;
color: White;
border: 1px solid black;
width:100%;
height:30px;
}
.ParentMenu:hover
{
font-family: Tahoma;
font-weight: bold;
padding-left: 6px;
padding-right: 6px;
text-align: center;
border: 1px solid black;
font-size: small;
}
.ChildMenu
{
background-color: #8B008B;
font-weight: bold;
font-family: Tahoma;
padding-top: 4px;
padding-bottom: 4px;
padding-right: 5px;
padding-left: 5px;
text-align: left;
font-size: small;
color: White;
border: 1px solid black;
}
.ChildMenu:hover
{
font-weight: bold;
font-family: Tahoma;
padding-top: 4px;
padding-bottom: 4px;
padding-right: 6px;
padding-left: 6px;
text-align: left;
font-size: small;
border: 1px solid black;
background-color: Black;
}
</style>
<div>
<asp:Menu DynamicSelectedStyle-Font-Italic="true" ID="dynamicMENU"
runat="server" style="position:absolute; top: 112px; left: 10px; height: 44px; margin-bottom: 0px;"
Orientation="Horizontal" DynamicVerticalOffset="4"
OnMenuItemClick="dynamicMENU_MenuItemClick">
<StaticMenuItemStyle Width="100" CssClass="ParentMenu" />
<DynamicMenuItemStyle Width="250" CssClass="ChildMenu" />
</asp:Menu>
</div>
// default.aspx.cs //
if (!this.IsPostBack)
{
GetMenu();
}
public void GetMenu()
{
DataSet dsParentMenu = getPARENTMENU();
DataRowCollection drcParentMenu = dsParentMenu.Tables[0].Rows;
DataSet dsChildMenuAll = getCHILDMENU();
DataTable drcChildMenuAll = dsChildMenuAll.Tables[0];
MenuItem mainMENUITEM;
MenuItem childMENUITEM;
foreach (DataRow drParentMenu in drcParentMenu)
{
mainMENUITEM = new MenuItem(drParentMenu["ParentMenu_Name"].ToString());
dynamicMENU.Items.Add(mainMENUITEM);
DataRow[] drcChildMenu = drcChildMenuAll.Select("Parent_ID=" + "'" + drParentMenu["ID"].ToString() + "'");
foreach (DataRow drSUBMENUITEM in drcChildMenu)
{
childMENUITEM = new MenuItem(drSUBMENUITEM["ChildMenu_Name"].ToString());
mainMENUITEM.ChildItems.Add(childMENUITEM);
childMENUITEM.NavigateUrl = drSUBMENUITEM["ChildMenu_URL"].ToString();
}
}
}
public DataSet getPARENTMENU()
{
SqlConnection myConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Pubs"].ToString());
string str_query = string.Empty;
str_query = "SELECT * FROM Parent_Menu";
SqlDataAdapter daPARENT = new SqlDataAdapter(str_query, myConnection);
DataSet dsTEMP = new DataSet();
daPARENT.Fill(dsTEMP, "tablePARENT");
return dsTEMP;
}
public DataSet getCHILDMENU()
{
SqlConnection myConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Pubs"].ToString());
string str_querychild = string.Empty;
str_querychild = "SELECT * FROM Child_Menu";
SqlDataAdapter daCHILD = new SqlDataAdapter(str_querychild, myConnection);
DataSet dsTEMP = new DataSet();
daCHILD.Fill(dsTEMP, "tableCHILD");
return dsTEMP;
}
protected void dynamicMENU_MenuItemClick(object sender, MenuEventArgs e)
{
Response.Redirect("~/Login1.aspx");
}
// DataBase Table //
1. Parent_Menu
<style type="text/css">
.ParentMenu
{
font-size: small;
font-family: Tahoma;
font-weight: bold;
padding-left: 6px;
padding-right: 6px;
text-align: center;
background-color: #8B008B;
color: White;
border: 1px solid black;
width:100%;
height:30px;
}
.ParentMenu:hover
{
font-family: Tahoma;
font-weight: bold;
padding-left: 6px;
padding-right: 6px;
text-align: center;
border: 1px solid black;
font-size: small;
}
.ChildMenu
{
background-color: #8B008B;
font-weight: bold;
font-family: Tahoma;
padding-top: 4px;
padding-bottom: 4px;
padding-right: 5px;
padding-left: 5px;
text-align: left;
font-size: small;
color: White;
border: 1px solid black;
}
.ChildMenu:hover
{
font-weight: bold;
font-family: Tahoma;
padding-top: 4px;
padding-bottom: 4px;
padding-right: 6px;
padding-left: 6px;
text-align: left;
font-size: small;
border: 1px solid black;
background-color: Black;
}
</style>
<div>
<asp:Menu DynamicSelectedStyle-Font-Italic="true" ID="dynamicMENU"
runat="server" style="position:absolute; top: 112px; left: 10px; height: 44px; margin-bottom: 0px;"
Orientation="Horizontal" DynamicVerticalOffset="4"
OnMenuItemClick="dynamicMENU_MenuItemClick">
<StaticMenuItemStyle Width="100" CssClass="ParentMenu" />
<DynamicMenuItemStyle Width="250" CssClass="ChildMenu" />
</asp:Menu>
</div>
// default.aspx.cs //
if (!this.IsPostBack)
{
GetMenu();
}
public void GetMenu()
{
DataSet dsParentMenu = getPARENTMENU();
DataRowCollection drcParentMenu = dsParentMenu.Tables[0].Rows;
DataSet dsChildMenuAll = getCHILDMENU();
DataTable drcChildMenuAll = dsChildMenuAll.Tables[0];
MenuItem mainMENUITEM;
MenuItem childMENUITEM;
foreach (DataRow drParentMenu in drcParentMenu)
{
mainMENUITEM = new MenuItem(drParentMenu["ParentMenu_Name"].ToString());
dynamicMENU.Items.Add(mainMENUITEM);
DataRow[] drcChildMenu = drcChildMenuAll.Select("Parent_ID=" + "'" + drParentMenu["ID"].ToString() + "'");
foreach (DataRow drSUBMENUITEM in drcChildMenu)
{
childMENUITEM = new MenuItem(drSUBMENUITEM["ChildMenu_Name"].ToString());
mainMENUITEM.ChildItems.Add(childMENUITEM);
childMENUITEM.NavigateUrl = drSUBMENUITEM["ChildMenu_URL"].ToString();
}
}
}
public DataSet getPARENTMENU()
{
SqlConnection myConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Pubs"].ToString());
string str_query = string.Empty;
str_query = "SELECT * FROM Parent_Menu";
SqlDataAdapter daPARENT = new SqlDataAdapter(str_query, myConnection);
DataSet dsTEMP = new DataSet();
daPARENT.Fill(dsTEMP, "tablePARENT");
return dsTEMP;
}
public DataSet getCHILDMENU()
{
SqlConnection myConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Pubs"].ToString());
string str_querychild = string.Empty;
str_querychild = "SELECT * FROM Child_Menu";
SqlDataAdapter daCHILD = new SqlDataAdapter(str_querychild, myConnection);
DataSet dsTEMP = new DataSet();
daCHILD.Fill(dsTEMP, "tableCHILD");
return dsTEMP;
}
protected void dynamicMENU_MenuItemClick(object sender, MenuEventArgs e)
{
Response.Redirect("~/Login1.aspx");
}
// DataBase Table //
1. Parent_Menu
2. Child_Menu
No comments:
Post a Comment