First Table
CREATE TABLE [dbo].[MenuControl](
[MenuId] [int] IDENTITY(1,1) NOT NULL,
[Title] [nvarchar](50) NULL,
[NavigateUrl] [nvarchar](max) NULL,
[IsActive] [char](10) NULL,
CONSTRAINT [PK_MenuControl] PRIMARY KEY CLUSTERED
Second Table
CREATE TABLE [dbo].[SubMenuControl](
[SubMenuId] [int] IDENTITY(1,1) NOT NULL,
[MenuId] [int] NULL,
[Title] [nvarchar](50) NULL,
[NavigateUrl] [nvarchar](max) NULL,
[IsActive] [char](10) NULL,
CONSTRAINT [PK_SubMenuControl] PRIMARY KEY CLUSTERED
Store Proceser
SELECT * from MenuControl
select * from SubMenuControl
and C# Coding
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("SP_SelectMenuCont", con);
cmd.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
adpt.Fill(ds);
con.Close();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Menu2.Items.Add(new MenuItem(ds.Tables[0].Rows[i]["Title"].ToString(), "", "", ds.Tables[0].Rows[i]["NavigateUrl"].ToString()));
for (int j = 0; j < ds.Tables[1].Rows.Count; j++)
{
if (ds.Tables[0].Rows[i]["MenuId"].ToString() == ds.Tables[1].Rows[j]["MenuId"].ToString())
{
Menu2.Items[i].ChildItems.Add(new MenuItem(ds.Tables[1].Rows[j]["Title"].ToString(), "", "", ds.Tables[1].Rows[j]["NavigateUrl"].ToString()));
}
}
}
This Formate Menu Create
Menu
1.SubMenu
1(i)SubMenu
1(ii)Sub Menu
1(iii) Submenu
2. Submenu
2(i) Submenu
2(ii) submenu