1. Create A Table.
CREATE TABLE [dbo].[MenuMaster](
[MenuID] [bigint] IDENTITY(1,1) NOT NULL,
[ParentId] [bigint] NOT NULL,
[MenuName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[MenuURL] [nvarchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL)
Insert INTO MenuMaster Values(0,'Dynamic','')
Insert INTO MenuMaster Values(0,'Data Bind Control','')
Insert INTO MenuMaster Values(0,'Ajax','')
Insert INTO MenuMaster Values(0,'Jquery','')
Insert INTO MenuMaster Values(0,'WCF & Web Services','')
Insert INTO MenuMaster Values(0,'Welcome Page','')
Insert INTO MenuMaster Values(2,'GridView','../aaaa.aspx')
Insert INTO MenuMaster Values(2,'Test','')
Insert INTO MenuMaster Values(8,'Chart','../Chart.aspx')
2. Create Procedure As-
-- Exec PR_PageMenu 0
Create PRoc PR_PageMenu @dispType Varchar(5)
As
select * From MenuMaster
3. Create A Page In Visual Studio.
<asp:Menu ID="Menu1" Target="frmPlace" runat="server" Orientation="Horizontal" Width="47%"
BackColor="#E3EAEB" DynamicHorizontalOffset="5" Font-Names="Verdana"
Font-Size="0.8em" ForeColor="#666666" Height="16px"
StaticSubMenuIndent="10px">
<DynamicHoverStyle CssClass="DynamicHover" BackColor="#666666"
ForeColor="White" />
<DynamicMenuItemStyle CssClass="DynamicMenuItem" HorizontalPadding="5px"
VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#E3EAEB" />
<DynamicSelectedStyle CssClass="DynamicHover" BackColor="#1C5E55" />
<StaticHoverStyle CssClass="staticHover" BackColor="#666666"
ForeColor="White" />
<StaticMenuItemStyle CssClass="StaticMenuItem" ItemSpacing="1px"
HorizontalPadding="5px" VerticalPadding="2px" />
<StaticSelectedStyle CssClass="staticHover" BackColor="#1C5E55" />
</asp:Menu>
</div><br /><br /><br /><br /><br /><br />
<div>
<iframe id="myIframe" class="setframe" name="frmPlace" runat="server" height="449px" width="100%"></iframe>
</div>
4. In Backend
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using MyFrameWork;
using System.Collections.Generic;
public partial class ProcessMaster_ProcessMaster : System.Web.UI.Page
{
MyDataUtility objutility = new MyDataUtility();
Dictionary<string, string> objpram = new Dictionary<string, string>();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!IsPostBack)
{
DataTable menuData = null;
try
{
menuData = new DataTable();
menuData = GetMenuData();
AddTopMenuItems(menuData);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
menuData = null;
}
}
}
}
private DataTable GetMenuData()
{
try
{
DataTable dtMenuItems = new DataTable();
objpram.Add("@dispType", "0");
dtMenuItems = objutility.GetDataTable("PR_PageMenu", objpram);
return dtMenuItems;
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
return null;
}
private void AddTopMenuItems(DataTable menuData)
{
DataView view = null;
try
{
view = new DataView(menuData);
view.RowFilter = "ParentID = 0";
foreach (DataRowView row in view)
{
MenuItem newMenuItem = new MenuItem(row["MenuName"].ToString(), row["MenuID"].ToString());
string currentURL = "";
//currentURL = Request.Url.ToString().Replace("Menu-Nitish/Menu.aspx", "");
newMenuItem.NavigateUrl = currentURL + row["MenuURL"].ToString();
Menu1.Items.Add(newMenuItem);
AddChildMenuItems(menuData, newMenuItem);
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
view = null;
}
}
private void AddChildMenuItems(DataTable menuData, MenuItem parentMenuItem)
{
DataView view = null;
try
{
view = new DataView(menuData);
view.RowFilter = "ParentID =" + parentMenuItem.Value;
foreach (DataRowView row in view)
{
MenuItem newMenuItem = new MenuItem(row["MenuName"].ToString(), row["MenuID"].ToString());
string currentURL = "";
newMenuItem.NavigateUrl = currentURL + row["MenuURL"].ToString();
HtmlControl myIframe = (HtmlControl)this.FindControl("myIframe");
myIframe.Attributes["src"] = currentURL + row["MenuURL"].ToString();
parentMenuItem.ChildItems.Add(newMenuItem);
AddChildMenuItems2(menuData, newMenuItem);
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
view = null;
}
}
private void AddChildMenuItems2(DataTable menuData, MenuItem parentMenuItem)
{
DataView view = null;
try
{
view = new DataView(menuData);
view.RowFilter = "ParentID =" + parentMenuItem.Value;
foreach (DataRowView row in view)
{
MenuItem newMenuItem = new MenuItem(row["MenuName"].ToString(), row["MenuID"].ToString());
string currentURL = "";
newMenuItem.NavigateUrl = currentURL + row["MenuURL"].ToString();
parentMenuItem.ChildItems.Add(newMenuItem);
//AddChildMenuItems3(menuData, newMenuItem);
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
view = null;
}
}
}
NOTE::
There May Error While You Browse This Page With IE & Chorme. To Stop This From
Happening Place This Code On Your Page.
protected void Page_PreInit(object sender, EventArgs e)
{
if (Request.UserAgent.Contains("AppleWebKit"))
Request.Browser.Adapters.Clear();
}
5. Now Run Your Page....
Cheers!!!
CREATE TABLE [dbo].[MenuMaster](
[MenuID] [bigint] IDENTITY(1,1) NOT NULL,
[ParentId] [bigint] NOT NULL,
[MenuName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[MenuURL] [nvarchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL)
Insert INTO MenuMaster Values(0,'Dynamic','')
Insert INTO MenuMaster Values(0,'Data Bind Control','')
Insert INTO MenuMaster Values(0,'Ajax','')
Insert INTO MenuMaster Values(0,'Jquery','')
Insert INTO MenuMaster Values(0,'WCF & Web Services','')
Insert INTO MenuMaster Values(0,'Welcome Page','')
Insert INTO MenuMaster Values(2,'GridView','../aaaa.aspx')
Insert INTO MenuMaster Values(2,'Test','')
Insert INTO MenuMaster Values(8,'Chart','../Chart.aspx')
2. Create Procedure As-
-- Exec PR_PageMenu 0
Create PRoc PR_PageMenu @dispType Varchar(5)
As
select * From MenuMaster
3. Create A Page In Visual Studio.
<asp:Menu ID="Menu1" Target="frmPlace" runat="server" Orientation="Horizontal" Width="47%"
BackColor="#E3EAEB" DynamicHorizontalOffset="5" Font-Names="Verdana"
Font-Size="0.8em" ForeColor="#666666" Height="16px"
StaticSubMenuIndent="10px">
<DynamicHoverStyle CssClass="DynamicHover" BackColor="#666666"
ForeColor="White" />
<DynamicMenuItemStyle CssClass="DynamicMenuItem" HorizontalPadding="5px"
VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#E3EAEB" />
<DynamicSelectedStyle CssClass="DynamicHover" BackColor="#1C5E55" />
<StaticHoverStyle CssClass="staticHover" BackColor="#666666"
ForeColor="White" />
<StaticMenuItemStyle CssClass="StaticMenuItem" ItemSpacing="1px"
HorizontalPadding="5px" VerticalPadding="2px" />
<StaticSelectedStyle CssClass="staticHover" BackColor="#1C5E55" />
</asp:Menu>
</div><br /><br /><br /><br /><br /><br />
<div>
<iframe id="myIframe" class="setframe" name="frmPlace" runat="server" height="449px" width="100%"></iframe>
</div>
4. In Backend
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using MyFrameWork;
using System.Collections.Generic;
public partial class ProcessMaster_ProcessMaster : System.Web.UI.Page
{
MyDataUtility objutility = new MyDataUtility();
Dictionary<string, string> objpram = new Dictionary<string, string>();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!IsPostBack)
{
DataTable menuData = null;
try
{
menuData = new DataTable();
menuData = GetMenuData();
AddTopMenuItems(menuData);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
menuData = null;
}
}
}
}
private DataTable GetMenuData()
{
try
{
DataTable dtMenuItems = new DataTable();
objpram.Add("@dispType", "0");
dtMenuItems = objutility.GetDataTable("PR_PageMenu", objpram);
return dtMenuItems;
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
return null;
}
private void AddTopMenuItems(DataTable menuData)
{
DataView view = null;
try
{
view = new DataView(menuData);
view.RowFilter = "ParentID = 0";
foreach (DataRowView row in view)
{
MenuItem newMenuItem = new MenuItem(row["MenuName"].ToString(), row["MenuID"].ToString());
string currentURL = "";
//currentURL = Request.Url.ToString().Replace("Menu-Nitish/Menu.aspx", "");
newMenuItem.NavigateUrl = currentURL + row["MenuURL"].ToString();
Menu1.Items.Add(newMenuItem);
AddChildMenuItems(menuData, newMenuItem);
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
view = null;
}
}
private void AddChildMenuItems(DataTable menuData, MenuItem parentMenuItem)
{
DataView view = null;
try
{
view = new DataView(menuData);
view.RowFilter = "ParentID =" + parentMenuItem.Value;
foreach (DataRowView row in view)
{
MenuItem newMenuItem = new MenuItem(row["MenuName"].ToString(), row["MenuID"].ToString());
string currentURL = "";
newMenuItem.NavigateUrl = currentURL + row["MenuURL"].ToString();
HtmlControl myIframe = (HtmlControl)this.FindControl("myIframe");
myIframe.Attributes["src"] = currentURL + row["MenuURL"].ToString();
parentMenuItem.ChildItems.Add(newMenuItem);
AddChildMenuItems2(menuData, newMenuItem);
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
view = null;
}
}
private void AddChildMenuItems2(DataTable menuData, MenuItem parentMenuItem)
{
DataView view = null;
try
{
view = new DataView(menuData);
view.RowFilter = "ParentID =" + parentMenuItem.Value;
foreach (DataRowView row in view)
{
MenuItem newMenuItem = new MenuItem(row["MenuName"].ToString(), row["MenuID"].ToString());
string currentURL = "";
newMenuItem.NavigateUrl = currentURL + row["MenuURL"].ToString();
parentMenuItem.ChildItems.Add(newMenuItem);
//AddChildMenuItems3(menuData, newMenuItem);
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
view = null;
}
}
}
NOTE::
There May Error While You Browse This Page With IE & Chorme. To Stop This From
Happening Place This Code On Your Page.
protected void Page_PreInit(object sender, EventArgs e)
{
if (Request.UserAgent.Contains("AppleWebKit"))
Request.Browser.Adapters.Clear();
}
5. Now Run Your Page....
Cheers!!!
No comments:
Post a Comment