如何使用getjson从数据库中获取菜单 [英] How to get menus from database using getjson

查看:83
本文介绍了如何使用getjson从数据库中获取菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在aspx.cs中处理Jquery,我已经创建了顶部标题和左侧标题


通过使用Getjson方法,我们需要从数据库调用菜单,因此我创建了像TopMenu和LeftMenu这样的数据库,两个表(TopMenu)包含
(MenuID | MenuName |
1 |首页
2 |产品

(LeftMenu)包含
(MenuID | MenuName |
1 |首页
2 |产品
通过使用GetJson方法,我们必须在top标题中的aspx应用程序TopMenu项中调用MenuName,在左标题中的leftMenu名称中调用MenuName,这样我就获得了顶部调用菜单bt我无法访问左侧bt,我在此调用时无法同时访问两个getjson code plz提前帮助我,我应该如何在应用程序中调用菜单

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

推荐答案

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());
        }
    }


如上问题,您需要制作edmx文件以从数据库中获取数据,然后如果您正在使用asp.net,则在此处编写代码.
如果您正在使用webapi,请查看以下代码

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

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


.get("api/MenuItem",function(data){ alert(data.toString()); 警报(1); if(data.length> 0){
.get("api/MenuItem", function (data) { alert(data.toString()); alert(1); if (data.length > 0) {


这篇关于如何使用getjson从数据库中获取菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆