Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
First Table
SQL
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

SQL
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

SQL
SELECT * from MenuControl
    select * from SubMenuControl


and C# Coding
C#
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
Posted
Updated 12-Oct-13 21:09pm
v3
Comments
OriginalGriff 12-Oct-13 10:55am    
And your question is?
You seem to have forgotten to tell us what the problem is...
Use the "Improve question" widget to edit your question and provide better information.
krishna97 12-Oct-13 10:58am    
Tree Formate Given Menu and Subment Create
krishna97 12-Oct-13 23:57pm    
Out Put given For Home--->Subhome

But MyProblem given
Home-->subhome-->SubHome
krishna97 12-Oct-13 23:58pm    
How Can Create MainMenu and Submenu--->SubmenuChild
BillWoodruff 13-Oct-13 0:12am    
Your code looks okay to me. I've done similar things in C# WinForms, building a MenuStrip, from input data, with no problem: in WinForms you'd add ToolStripMenuItems to the DropDownItems Collection of a Top-Level MenuItem (which is also of Type ToolStripMenuItem).

You need to show your current output and state exactly what the difference is between that and the output you want. I can't read your mind.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900