2013-09-26 125 views
0

我在我的項目中有這個模塊,其中有2個gridviews。一個用於Main MenuModule,另一個用於子菜單。我創建了一個List,這樣當我的Main Menu Module上的一行被選中並且它有一個對應的子菜單時,它將顯示在SubMenu Gridview上。將列表添加到會話中

我的問題是如何把這個列表到會話,以便我,當我瀏覽到另一個頁面,然後回到這個頁面,子菜單的GridView依然存在。

這是我的代碼列表。

protected void cbxSelect_CheckedChanged(object sender, EventArgs e) 
     { 

    SubMenuGrid.DataSource = null; 
    SubMenuGrid.DataBind(); 

    Business.SubMenuModules sub = new Business.SubMenuModules(); 

    List<oSubList> oList = new List<oSubList>(); 

    int counter = 0; 

    foreach (GridViewRow nRow in gvModuleList.Rows) 
    { 
     Int32 intModID = Convert.ToInt32(nRow.Cells[0].Text); 
     CheckBox chkBx = (CheckBox)nRow.FindControl("cbxSelect"); 

     if (chkBx.Checked == true) 
     { 
      counter = counter + 1; 

      var oModList = sub.GetAllMenuPerModuleID(intModID); 

      if (oModList.Count > 0) 
      { 

       foreach (var rec in oModList) 
       { 
        oSubList olist = new oSubList 
        { 
         ID = rec.ID, 
         ModuleID = rec.ModuleID, 
         Submenu = rec.Submenu, 
         Description = rec.Description 
        }; 
        oList.Add(olist);  
       } 

       SubMenuGrid.DataSource = oList; 
       SubMenuGrid.DataBind(); 
      } 
     } 
+0

爲什麼你想在會議上?你不想保存更改嗎? –

+0

他去與狀態管理bcoz,值可以將網頁的過期後也被保留.. – Sasidharan

+0

我不想把它保存在我的數據庫呢,我只是想臨時存儲它,這樣,當我在提交前返回到該頁面,我可以看到我的子菜單中的GridView .. – theNoobie

回答

0

只要將列表傳遞給會話[「list」]。
在頁面加載檢查用戶的狀態和會話的值賦給菜單..

protected void cbxSelect_CheckedChanged(object sender, EventArgs e) 
     { 

     SubMenuGrid.DataSource = null; 
     SubMenuGrid.DataBind(); 

     Business.SubMenuModules sub = new Business.SubMenuModules(); 

     List<oSubList> oList = new List<oSubList>(); 

     int counter = 0; 

     foreach (GridViewRow nRow in gvModuleList.Rows) 
     { 
      Int32 intModID = Convert.ToInt32(nRow.Cells[0].Text); 
      CheckBox chkBx = (CheckBox)nRow.FindControl("cbxSelect"); 

      if (chkBx.Checked == true) 
      { 
       counter = counter + 1; 

       var oModList = sub.GetAllMenuPerModuleID(intModID); 

       if (oModList.Count > 0) 
       { 

        foreach (var rec in oModList) 
        { 
         oSubList olist = new oSubList 
         { 
          ID = rec.ID, 
          ModuleID = rec.ModuleID, 
          Submenu = rec.Submenu, 
          Description = rec.Description 
         }; 
         oList.Add(olist);  
        } 

        Session["list"]=oList; 

        SubMenuGrid.DataSource = oList; 
        SubMenuGrid.DataBind(); 
       } 
      } 
+0

嗨,會是這樣的,如果我通過它在頁面加載 保護無效btnNext_Click(對象發件人,ImageClickEventArgs E) { oList =會話[「清單」] 的Response.Redirect(「〜 /Forms/RegReason.aspx「); } – theNoobie

+0

是的,它會,但你必須恢復通過檢查當前登錄的用戶或something..after檢查視圖只是會話值傳遞給電網.. – Sasidharan

+0

嗨,感謝您的快速反應!它會是這樣如果我把它傳遞給頁面加載? oList = Session [「list」]應該是什麼索引? – theNoobie

0

只是分配列表會話簡單,並調用它的子菜單頁面上。

MainMenu的頁面

Session["list"]=oList; 

子菜單頁面上

List<oSubList> subList = (List<oSubList>) Session["list"];