2017-02-18 26 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菜單欄回發 –