Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi i am working on Jquery in aspx.cs i had created top header and left header


by Using Getjson Method we need to call menus from database so i had created database like TopMenu and LeftMenu two tables( TopMenu) contains
(MenuID|MenuName|
1 |Home
2 |product
and
(LeftMenu) contains
(MenuID|MenuName|
1 |Home
2 |product
by using GetJson method we have to call MenuName in aspx application TopMenu items in topheader and leftMenu names in left header so i had got top calling menus bt i can't access the left bt i nedd to access both at a time this my calling getjson code plz help me thanks in advance how should i call menus in my application
Posted
Updated 5-Apr-12 2:50am
v2

C#
protected void Page_Load(object sender, EventArgs e)
    {       
            filltree();        
    }

    public void filltree()
   {
       setConnectionString();
        
       query = "select * from menulist_parent ";

       DataSet ds = EmpBal.treeviewBAL(query, conString);
       TreeView1.Nodes.Clear();
       
       foreach (DataRow dr in ds.Tables[0].Rows)
       {
           TreeNode tnparent = new TreeNode();

           tnparent.Text  = dr["parentname"].ToString();
           tnparent.Value = dr["parentid"].ToString();
           tnparent.PopulateOnDemand = true;
           tnparent.ToolTip = "get one child";
           tnparent.SelectAction = TreeNodeSelectAction.SelectExpand;
           tnparent.Expand();
           tnparent.Selected = true;
           TreeView1.Nodes.Add(tnparent);
           fillchild(tnparent, tnparent.Value);
       }
    }

    public void fillchild(TreeNode parent,string parentid)

   {               
       setConnectionString();
       query = "select * from menulist_child";

       DataSet ds = EmpBal.treeviewchildBAL(query, conString);
       parent.ChildNodes.Clear();

       foreach (DataRow dr in ds.Tables[0].Rows)
       {           
           TreeNode child = new TreeNode();
           child.Text = dr["childname"].ToString();
           child.Value = dr["childid"].ToString();
           child.NavigateUrl = dr["url"].ToString();
           if (child.ChildNodes.Count == 0)
           {
               child.PopulateOnDemand = true;
           }

           child.ToolTip = "";
           child.SelectAction = TreeNodeSelectAction.SelectExpand;
           child.CollapseAll();
           parent.ChildNodes.Add(child);
          }
    }
    public void setConnectionString()
    {
        try
        {
            conString = System.Configuration.ConfigurationManager.ConnectionStrings["masterConnectionString1"].ToString();
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
 
Share this answer
 
v2
As above question u need to made edmx file to fectch data from database from then write the code here if u are working for asp.net take url and paste at url
if u are working for webapi look this code

XML
<script type="text/javascript">
    //ApycomDesing Starts here //

    $.get("api/MenuItem", function (data) {

        alert(data.toString());
        alert(1);

        if (data.length > 0) {
            $("#menu").append('<ul id="" class="menu">');

            $.each(data, function (index, dataMenu) {
                var stringBuilder = [];
                stringBuilder.push('<li class=""><a href="javascript:void(0)" id="" class="parent">' + dataMenu.MenuName + '</a>');
                alert(stringBuilder.toString());
                alert(2);

               if (dataMenu.SubMenuName != null) {
                               var submenu = [];
                               submenu = dataMenu.SubMenuName;
                               var splittedmenus = [];
                              splittedmenus = submenu.split(",");
                               alert(splittedmenus.length);
                                       stringBuilder.push('<div><ul>');
                                       for (var i = 0; i < splittedmenus.length; i++) {
                                           stringBuilder.push('<li ><a href="#" class="parent" ><span>' + splittedmenus[i] + '</span></a>');
                                           alert(stringBuilder.toString());
                        if (dataMenu.SubMenus != null)
                        {
                            var ssubmenu = [];
                            ssubmenu = dataMenu.SubMenus;
                            var splittingSsub = [];

                            splittingSsub = ssubmenu.split(',');
                            alert(splittingSsub.toString());
                            alert('3');
                            stringBuilder.push('<div><ul>');
                            for (var j = 0; j < splittingSsub.length; j++) {
                                alert('start ssub loop');
                                stringBuilder.push('<li><a href="#"  ><span>' + splittingSsub[j] + '</span></a></li>');
                                alert(stringBuilder.toString());
                                alert(4);
                            }
                            stringBuilder.push('</ul></div>');
                            alert('5');
                        }
                        alert('endloop');
                        stringBuilder.push('</li>');

                    }
                    stringBuilder.push('</ul></div>');


                }

                stringBuilder.push('</li>');

                $(".menu").append(stringBuilder.join(''));
            });
        }
    });

    </script>
 
Share this answer
 
you can fetch the data from data base for menus
 
Share this answer
 

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