2017-02-18 28 views
0

我创建每个用户都拥有一组Web表单的访问和特定的一组不是一个多用户应用避免菜单的数据绑定(几乎30类型的配置文件)在每次回发使用

我已经创建了两个表菜单主和子菜单主和添加的网址和父子关系

我正在使用一个Infragistic WebExplorer作为导航控件内的一个用户控件,我正在做UserControl后面的所有数据绑定。

我的问题是每当用户单击WebExplorer控件获取数据绑定并重新呈现控件时。造成应用程序很慢

protected void Page_Load(object sender, EventArgs e) 
     { 

       loadexplorerebar(); 


     } 



     public void getMenuData() 
     { 
      SqlCommand cmd = new SqlCommand("select * from MainMenuMaster"); 

      DataTable dt = ReturnQueryResultDatatable(cmd); 

      SqlCommand cmd1 = new SqlCommand(@"SELECT  SubMenuMaster.Menu_PK, SubMenuMaster.MenuText, SubMenuMaster.MenuURL, SubMenuMaster.ParentID, SubMenuMaster.isEnable, SubMenuMaster.IsNormal 
FROM   SubMenuMaster INNER JOIN 
         UserProfileRights ON SubMenuMaster.Menu_PK = UserProfileRights.Menu_PK 
WHERE(UserProfileRights.UserProfile_Pk = @Param2)"); 
      cmd1.Parameters.AddWithValue("", int.Parse(Session["UserProfile_Pk"].ToString())); 
      DataTable dt2 = ReturnQueryResultDatatable(cmd1); 

      Session["MainMenuMaster"] = dt; 
      Session["SubMenuMaster"] = dt2; 

     } 


     public void loadexplorerebar() 
     { 
      DataTable dt = null; 
      DataTable dt2 = null; 

      if (Session["MainMenuMaster"]==null || Session["SubMenuMaster"]==null) 
      { 
       getMenuData(); 
      } 
      else 
      { 
       dt = (DataTable)Session["MainMenuMaster"]; 
       dt2 = (DataTable)Session["SubMenuMaster"]; 

      }    


      if (dt != null) 
      { 
       for (int i = 0; i < dt.Rows.Count; i++) 
       { 
        ExplorerBarGroup grp = new ExplorerBarGroup(); 
        grp.Text = dt.Rows[i]["MainmenuName"].ToString(); 
        this.WebExplorerBar1.Groups.Add(grp); 
        int MAINMENU_PK = int.Parse(dt.Rows[i]["mAINmENU_pk"].ToString()); 
        try 
        { 

         DataTable mainmenuchild = dt2.Select("parentid=" + MAINMENU_PK + "").CopyToDataTable(); 

         foreach (DataRow drow in mainmenuchild.Rows) 
         { 

          int childid = int.Parse(drow["Menu_PK"].ToString()); 
          ExplorerBarItem item = new ExplorerBarItem(); 
          item.Text = drow["MenuText"].ToString(); 
          item.NavigateUrl = drow["MenuURL"].ToString(); 
          grp.Items.Add(item); 
          try 
          { 
           getnewItem(item, childid, dt2); 
          } 
          catch (Exception) 
          { 


          } 
         } 
        } 
        catch (Exception) 
        { 


        } 


       } 


      } 

     } 



     public void getnewItem(ExplorerBarItem item, int parentid, DataTable mainmenuchild) 
     { 

      DataTable mainmenuchildtemp = mainmenuchild.Select("parentid=" + parentid + "").CopyToDataTable(); 
      foreach (DataRow drow in mainmenuchildtemp.Rows) 
      { 

       try 
       { 
        int childid = int.Parse(drow["Menu_PK"].ToString()); 
        ExplorerBarItem itemnum = new ExplorerBarItem(); 
        itemnum.Text = drow["MenuText"].ToString(); 
        itemnum.NavigateUrl = drow["MenuURL"].ToString(); 
        item.Items.Add(itemnum); 
        getnewItem(itemnum, childid, mainmenuchild); 
       } 
       catch (Exception) 
       { 
        ; 
       } 
      } 
     } 

和我的HTML标记就像下面

<ig:WebExplorerBar ID="WebExplorerBar1" runat="server" Width="250px"> 
</ig:WebExplorerBar> 

任何人都可以建议我如何避免这个数据

+0

也许你可以在viewstate中保存数据....一些IG控件支持避免数据绑定在后期并依赖视图状态的可能性。您可以节省从存储库获取数据的时间。当然,如果回发,您必须避免加载数据检查 –

+1

尝试将autopostback-itemclick和itemselected设置为关闭。然后WebExplorerBar应该停止发回每个项目点击。 http://www.infragistics.com/help/aspnet/infragistics4.web.v16.2~infragistics.web.ui.navigationcontrols.explorerbarautopostbackflags_members –

回答

0

把你的loadexplorerebar在每次回发绑定();方法内! ispostback

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!IsPostBack) 
    { 
     loadexplorerebar(); 
    } 
} 
+0

添加回发将停止postback的数据绑定和呈现infragistic菜单栏回发 –