我的项目中有这个模块,我有2个网格视图。一个用于Main MenuModule,另一个用于它的subMenu。我创建了一个List,这样当我的主菜单模块上的一行被检查并且它有一个相应的子菜单时,它将显示在SubMenu Gridview上。
我的问题在于如何将此列表放入会话中,以便当我导航到另一个页面然后返回到此页面时,SubMenu 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)
只需将列表传递给会话[“列表”] 页面加载检查用户的条件并将会话值分配给菜单..
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();
}
}
答案 1 :(得分:0)
只需将您的列表简单地分配给会话,然后在子菜单页面上调用它。
主页上的
Session["list"]=oList;
在子菜单页面
List<oSubList> subList = (List<oSubList>) Session["list"];