您的位置:程序门 -> .net技术 -> c#



自动生成菜单太多


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


自动生成菜单太多[已结贴,结贴人:]
发表于:2007-01-15 15:31:59 楼主
dataset   ds1   =   new   dataset();
                                ds1.readxml(application.startuppath   +   "/xml/user1.xml ");
                                dataset   ds2   =   new   dataset();
                                ds2.readxml(application.startuppath   +   "/xml/user2.xml ");
                                dataset   ds3   =   new   dataset();
                                ds3.readxml(application.startuppath   +   "/xml/user3.xml ");
                                dataset   ds4   =   new   dataset();
                                ds4.readxml(application.startuppath   +   "/xml/user4.xml ");
                               
                                foreach   (datarow   row1   in   ds1.tables[0].rows)
                                {
                                        if   (row1[2].tostring()   ==   "0 ")//生成第一级别国家
                                        {
                                                toolstripmenuitem   toolmenuitem   =   new   toolstripmenuitem();
                                                toolmenuitem.name   =   "toolmenuitem "   +   row1[0].tostring();
                                                toolmenuitem.text   =   row1[1].tostring();
                                                this.stripmenuitem_choose.dropdownitems.add(toolmenuitem);
                                                toolmenuitem.click   +=   new   system.eventhandler(this.toolmenuitem_click);

                                                if   (depth   > =   1)//当前的选定项
                                                {
                                                        if   (row1[0].tostring()   ==   area[0].tostring())
                                                        {
                                                                toolmenuitem.checked   =   true;
                                                        }
                                                }

                                                foreach   (datarow   row2   in   ds2.tables[0].rows)
                                                {
                                                        if   (row1[0].tostring()   ==   row2[3].tostring())//生成第二级别省份
                                                        {
                                                                //messagebox.show(row2[3].tostring());
                                                                toolstripmenuitem   toolmenuitem2   =   new   toolstripmenuitem();
                                                                toolmenuitem2.name   =   "toolmenuitem "   +   row2[0].tostring();
                                                                toolmenuitem2.text   =   row2[1].tostring();
                                                                toolmenuitem.dropdownitems.add(toolmenuitem2);
                                                                toolmenuitem2.click   +=   new   system.eventhandler(this.toolmenuitem_click);
                                                               
                                                                if   (depth   > =   2)//当前的选定项
                                                                {
                                                                        if   (row2[0].tostring()   ==   area[1].tostring())
                                                                        {
                                                                                toolmenuitem2.checked   =   true;
                                                                        }
                                                                }
                                                                else   if   (depth==1)  
                                                                {
                                                                        toolmenuitem2.checked   =   true;
                                                                }

                                                               
                                                                foreach   (datarow   row3   in   ds3.tables[0].rows)
                                                                {

                                                                        if   (row2[0].tostring()   ==   row3[3].tostring())//生成第三级别地区
                                                                        {
                                                                                //messagebox.show(row2[3].tostring());
                                                                                toolstripmenuitem   toolmenuitem3   =   new   toolstripmenuitem();
                                                                                toolmenuitem3.name   =   "toolmenuitem "   +   row3[0].tostring();
                                                                                toolmenuitem3.text   =   row3[1].tostring();
                                                                                toolmenuitem2.dropdownitems.add(toolmenuitem3);
                                                                                toolmenuitem3.click   +=   new   system.eventhandler(this.toolmenuitem_click);
                                                                               
                                                                                if   (depth   > =   3)//当前的选定项
                                                                                {
                                                                                        if   (row3[0].tostring()   ==   area[2].tostring())
                                                                                        {
                                                                                                toolmenuitem3.checked   =   true;
                                                                         
          .....略                                                                                      
                                                                                                   
                                            我的程序每次启动都要生成这样地区县市的三千多个菜单
本来读去数据库的现在已经用xml缓存了
可是发现更占资源
程序几乎打不开了
怎么样不用让它每次启动都要生成菜单啊
发表于:2007-01-16 09:33:071楼 得分:0
谁帮忙优化一下啊
我可以把整段代码发他
发表于:2007-01-16 09:40:262楼 得分:0
-_-@@

加载大菜单应该用分步形式。
一开始就显示国家的部分,人家选择了某国,再显示下级......
发表于:2007-01-16 10:40:493楼 得分:0
嗯,采用分级加载,不要以开始就加载所有的菜单,需要时才加载
发表于:2007-01-16 10:51:004楼 得分:0
我也是楼上的方法
发表于:2007-01-16 12:27:535楼 得分:0
谢谢哦
发表于:2007-04-18 11:55:226楼 得分:0
up


快速检索

最新资讯
热门点击