Click here to Skip to main content
15,896,118 members

how to show subitem of the menu on only clicking the parent menu not on mouse over

software_Engi08 asked:

Open original thread
Hi I want that when i take the mouse over the menu, I dont want to show submenu.the submenu should only be display on clicking the parent item. I have writen code as
XML
<asp:Menu ID="Menu1" runat="server" BackColor="#FFFBD6" DynamicHorizontalOffset="2"
           Font-Names="Verdana" Font-Size="0.8em" ForeColor="#990000" Orientation="Horizontal" StaticSubMenuIndent="10px" Style="z-index: 112; left: 205px;
           position: absolute; top: 14px">
           <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
           <DynamicHoverStyle BackColor="#990000" ForeColor="White" />
           <DynamicMenuStyle BackColor="#FFFBD6" />
           <StaticSelectedStyle BackColor="#FFCC66" />
           <DynamicSelectedStyle BackColor="#FFCC66" />
           <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
           <StaticHoverStyle BackColor="#990000" ForeColor="White" />
       </asp:Menu>
   and in the code behinde file as   protected void Page_Load(object sender, EventArgs e)
   {
       if (Page.IsPostBack == false)
       {
           DataTable dt = new DataTable();
           DataTable dt1 = new DataTable();

           // DataTable dt2 = new DataTable();

           TextBox3.Visible = false;
           Label3.Visible = false;
           Label2.Text = "Password";
           // Menu m = new Menu();
           string cn = "Data Source=hcl;Initial Catalog=mydata;Integrated Security=True";
           SqlConnection con = new SqlConnection(cn);
           SqlCommand cmd = new SqlCommand("select parentname,id from menu ", con);
           con.Open();
           cmd.CommandType = CommandType.Text;
           SqlDataReader dr = cmd.ExecuteReader();
           dt.Load(dr);
           for (int count = 0; count < dt.Rows.Count; count++)
           {

               MenuItem mnuLinkItem = new MenuItem();
               mnuLinkItem.Text = dt.Rows[count]["parentname"].ToString();
               mnuLinkItem.Value = dt.Rows[count]["id"].ToString();
               string menuid = mnuLinkItem.Value;
               // mnuLinkItem.NavigateUrl = datatable.Rows[count][1].ToString();

               Menu1.Items.Add(mnuLinkItem);

               string str = "select subname from submenu where subid=" + menuid + "order by menuorder asc";
               SqlCommand cmd1 = new SqlCommand(str, con);
               cmd1.CommandType = CommandType.Text;
               SqlDataReader dr1 = cmd1.ExecuteReader();
               dt1 = new DataTable();
               dt1.Load(dr1);

               int count2 = dt1.Rows.Count;
               for (int j = 0; j < count2; j++)
               {

                   MenuItem mnuLinkItem1 = new MenuItem();
                   mnuLinkItem1.Text = dt1.Rows[j]["subname"].ToString();
                   mnuLinkItem.ChildItems.Add(mnuLinkItem1);
                   // mnuLinkItem.NavigateUrl = datatable.Rows[count][1].ToString();

                   // mnuLinkItem1.ChildItems.AddAt(count2, mnuLinkItem1); //meun.Items.Add(mnuLinkItem);
                   //Menu1.Items.AddAt(count2, mnuLinkItem1);
                   //dr2.Close();
               }


           }
           con.Close();

       }
   }

Please help I want a exact code for it please help..
Tags: ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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