多级下拉菜单(动态)

HomePage.JPG
-------------------------------------
源代码下载/Files/singlepine/topmenu.rar

None.gif public   class  TopMenu : System.Web.UI.Page
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
protected DataRow[] father;
InBlock.gif    
protected DataRow[] first;
InBlock.gif    
protected DataRow[] second;
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
ExpandedSubBlockEnd.gif        }

InBlock.gif    
public static string ConnectionString=System.Configuration .ConfigurationSettings .AppSettings["ConnectionString"];
InBlock.gif    
ContractedSubBlock.gifExpandedSubBlockStart.gif        
GetDataSet#region GetDataSet
InBlock.gif        
public static DataSet GetDataSet(string sql)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            SqlDataAdapter    sda 
=new SqlDataAdapter(sql,ConnectionString);
InBlock.gif            DataSet ds
=new DataSet();
InBlock.gif            sda.Fill(ds);
InBlock.gif            
return ds;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif        
Web Form Designer generated code#region Web Form Designer generated code
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**//**//// <summary>
InBlock.gif        
/// Required method for Designer support - do not modify
InBlock.gif        
/// the contents of this method with the code editor.
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ContractedSubBlock.gifExpandedSubBlockStart.gif    
LoadTopMenu#region LoadTopMenu
InBlock.gif    
protected string LoadTopMenu()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
//IsBoot设置菜单级别,0一级,1二级,2三级,依此类推.
InBlock.gif
        string sqlFather="select * from topmenu order by IsBoot";
InBlock.gif        DataSet dsFather
=GetDataSet(sqlFather);
InBlock.gif        father
=dsFather.Tables[0].Select("IsBoot=0","IsBoot");
InBlock.gif        
string menu="";            
InBlock.gif        
int one=0;
InBlock.gif        
int two=1;
InBlock.gif        
int three=1;
InBlock.gif        
foreach(DataRow drfather in father)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{                
InBlock.gif            menu
+="mpmenu"+one+"=new mMenu("+"'"+drfather["text"]+"'"+",'/','self','','','','');";
InBlock.gif            first
=dsFather.Tables[0].Select("ParentID='"+Convert.ToInt32(drfather["ID"])+"' and IsBoot=1","IsBoot");
InBlock.gif            
foreach(DataRow drfirst in first)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                second
=dsFather.Tables[0].Select("ParentID='"+Convert.ToInt32(drfirst["ID"])+"' and IsBoot=2","IsBoot");
InBlock.gif                
if(second.Length==0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    menu
+="mpmenu"+one+".addItem(new mMenuItem("+"'"+drfirst["text"]+"'";//description
InBlock.gif
                    menu+=","+"'"+drfirst["url"]+"'"+",";//url
InBlock.gif
                    menu+="'"+drfirst["target"]+"'"+",";//target
InBlock.gif
                    menu+=""+drfirst["visible"]+",";//是否可见,false可见,true不可见
InBlock.gif
                    menu+="'"+drfirst["status"]+"'"+",";//状态条
InBlock.gif
                    menu+="null,'','','',''));";
ExpandedSubBlockEnd.gif                }

InBlock.gif                
foreach(DataRow drsecond in second)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{    
InBlock.gif                    menu
+="msub"+two+"=new mMenuItem("+"'"+drfirst["text"]+"','',"+"'"+drfirst["target"]+"'";
InBlock.gif                    menu
+=","+drfirst["visible"]+",";//是否可见,false可见,true不可见
InBlock.gif
                    menu+="'','1','','','','');";
InBlock.gif
InBlock.gif                    menu
+="msub"+three+".addsubItem(new mMenuItem("+"'"+drsecond["text"]+"'";//description
InBlock.gif
                    menu+=","+"'"+drsecond["url"]+"'"+",";//url
InBlock.gif
                    menu+="'"+drsecond["target"]+"'"+",";//target
InBlock.gif
                    menu+=""+drsecond["visible"]+",";//是否可见,false可见,true不可见
InBlock.gif
                    menu+="'"+drsecond["status"]+"'"+",";//状态条
InBlock.gif
                    menu+="null,'','','',''));";
InBlock.gif                    menu
+="mpmenu"+one+".addItem(msub"+two+");";//addItem
InBlock.gif
                    three++;
ExpandedSubBlockEnd.gif                }

InBlock.gif                two
++;
ExpandedSubBlockEnd.gif            }

InBlock.gif            one
++;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
return menu;
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif    
#endregion

ExpandedBlockEnd.gif}

3.数据库脚本
 

None.gif -- 建表
None.gif
if   exists  ( select   *   from  dbo.sysobjects  where  id  =   object_id (N ' [dbo].[topmenu] ' and   OBJECTPROPERTY (id, N ' IsUserTable ' =   1 )
None.gif
drop   table   [ dbo ] . [ topmenu ]
None.gif
GO
None.gif
None.gif
CREATE   TABLE   [ dbo ] . [ topmenu ]  (
None.gif    
[ ID ]   [ int ]   NOT   NULL  ,
None.gif    
[ parentId ]   [ int ]   NOT   NULL  ,
None.gif    
[ text ]   [ nvarchar ]  ( 255 ) COLLATE Chinese_PRC_CI_AS  NULL  ,
None.gif    
[ url ]   [ nvarchar ]  ( 255 ) COLLATE Chinese_PRC_CI_AS  NULL  ,
None.gif    
[ target ]   [ nvarchar ]  ( 50 ) COLLATE Chinese_PRC_CI_AS  NULL  ,
None.gif    
[ IsBoot ]   [ int ]   NULL  ,
None.gif    
[ visible ]   [ nvarchar ]  ( 50 ) COLLATE Chinese_PRC_CI_AS  NULL  ,
None.gif    
[ status ]   [ nvarchar ]  ( 50 ) COLLATE Chinese_PRC_CI_AS  NULL  
None.gif
ON   [ PRIMARY ]
None.gif
GO
None.gif
None.gif
-- 插入测试数据
None.gif
insert   into  topmenu( [ ID ] , [ parentId ] , [ text ] , [ url ] , [ target ] , [ IsBoot ] , [ visible ]  , [ status ] )
None.gif
values ( 1 , 0 , ' 深圳 ' , ' http://singlepine.cnblogs.com/articles/259955.html ' , ' self ' , 0 , ' false ' , ' 深圳 ' )
None.gif
None.gif
insert   into  topmenu( [ ID ] , [ parentId ] , [ text ] , [ url ] , [ target ] , [ IsBoot ] , [ visible ]  , [ status ] )
None.gif
values ( 2 , 1 , ' 南山 ' , ' http://singlepine.cnblogs.com/articles/259955.html ' , ' self ' , 1 , ' false ' , ' 南山 ' )
None.gif
None.gif
insert   into  topmenu( [ ID ] , [ parentId ] , [ text ] , [ url ] , [ target ] , [ IsBoot ] , [ visible ]  , [ status ] )
None.gif
values ( 3 , 1 , ' 福田 ' , ' http://singlepine.cnblogs.com/articles/259955.html ' , ' self ' , 1 , ' false ' , ' 福田 ' )
None.gif
None.gif
insert   into  topmenu( [ ID ] , [ parentId ] , [ text ] , [ url ] , [ target ] , [ IsBoot ] , [ visible ]  , [ status ] )
None.gif
values ( 4 , 2 , ' 科技园 ' , ' http://singlepine.cnblogs.com/articles/259955.html ' , ' self ' , 2 , ' false ' , ' 科技园 ' )
None.gif
None.gif
insert   into  topmenu( [ ID ] , [ parentId ] , [ text ] , [ url ] , [ target ] , [ IsBoot ] , [ visible ]  , [ status ] )
None.gif
values ( 5 , 3 , ' 塞格 ' , ' http://singlepine.cnblogs.com/articles/259955.html ' , ' self ' , 2 , ' false ' , ' 塞格 ' )
None.gif
None.gif
insert   into  topmenu( [ ID ] , [ parentId ] , [ text ] , [ url ] , [ target ] , [ IsBoot ] , [ visible ]  , [ status ] )
None.gif
values ( 6 , 0 , ' 广州 ' , ' http://singlepine.cnblogs.com/articles/259955.html ' , ' self ' , 0 , ' false ' , ' 广州 ' )
None.gif
None.gif
insert   into  topmenu( [ ID ] , [ parentId ] , [ text ] , [ url ] , [ target ] , [ IsBoot ] , [ visible ]  , [ status ] )
None.gif
values ( 7 , 6 , ' 广州火车站 ' , ' http://singlepine.cnblogs.com/articles/259955.html ' , ' self ' , 1 , ' false ' , ' 广州火车站 ' )

转载于:https://www.cnblogs.com/hzuIT/articles/752500.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值