如何将会话变量数组的值无效为null [英] How to nullify value of array of session variable to null

查看:96
本文介绍了如何将会话变量数组的值无效为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天.

在这里,我正在开发具有五个DropDownList控件(级联)的应用程序,该功能具有在没有子树可用时自动隐藏的功能,以及将"SelectedItem" ID存储到五个会话变量的功能,到目前为止,很好,但是当我触发上层(例如,第二个DDL及其在Session ["s3"]中在DDL3中有子树)的DDL选择时,如果新结果没有生成子树,它将隐藏第三个DDL(i' (很高兴),但其Session值未更改为null,请尝试满足我的要求,请检查我的代码

Hi, good day.

Here i''m developing a application with five DropDownList Controls (cascading), with functionality to hide automatically when no sub-tree is availabe, along with that i''m storing "SelectedItem" IDs to five session variables, upto now everything is fine, but when i trigger selectionevent of upper(say 2nd DDL which is having a subtree in DDL3 along with Session["s3"]) DDL selection, if the new result doen''t generate a subtree it hides 3rd DDL (i''m happy) but its Session value is not changing to null, here give a try to readch my requirement, please check my code

// Global variables with private acess level 
string _L1, _L2, _L3, _L4, _L5; 

string[] Values; 

_L1 = _L2 = _L3 = _L4 = _L5 = null; // in PageLOading (!Page.IsPostback) 

public void HideRemainingDDLs(DropDownList _ddlname) 
{ 
// _ddlname is the name of DropDownList, which doesn''t have a sub-tree, in our case DDL2 

 
 // 
_L1 = Session["L1ID"] == null ? null : Session["L1ID"].ToString(); 
_L2 = Session["L2ID"] == null ? null : Session["L2ID"].ToString(); 
_L3 = Session["L3ID"] == null ? null : Session["L3ID"].ToString(); 
_L4 = Session["L4ID"] == null ? null : Session["L4ID"].ToString(); 
_L5 = Session["L5ID"] == null ? null : Session["L5ID"].ToString(); 

UpdatePanel up = (UpdatePanel)TagEditor; 

Values = new string[5] { _L1, _L2, _L3, _L4, _L5 }; // Storing Session Variable as a string array 

if (up.HasControls()) 
{ 
foreach (Control subCtrl in up.Controls[0].Controls) 
{ 
if (subCtrl is DropDownList) // Check only if the Controls is a DropDownList 
{ 
DropDownList ddl = subCtrl as DropDownList; 
if (ddl.Visible == true) // Check only visible controls 
{ 
if (ddl != null && ddl.TabIndex > _ddlname.TabIndex) // DDL TabIndex starts from 0 
{ 
int i = ddl.TabIndex; 
Values[i] = null; 
ddl.Visible = false; // Hide the current DDL 
ddl.Items.Clear(); // remove all items in the DDL 
} 
} 
} 
} 
} 
} 


Example DDL SelectedIndexChanged Event 

protected void DDLSubL1_SelectedIndexChanged(object sender, EventArgs e) 
{ 
if (populate("PopulateL2Subjects", DDLSubL2, DDLSubL1, out _subject1)) // method to retive data from DB, returns bool value. 
{ 
DDLSubL2.Visible = true; 
} 
else 
{ 
HideRemainingDDLs(DDLSubL1); // Method which is implemented above 
DDLSubL2.Items.Add("Select chapter"); 
} 
// set the value irrespective of new list. 
Session["L1ID"]= _subject1; 
} 

推荐答案

只需在以下行添加
会话["L" + i +"ID"] = null;

删除
值[i] = null;
Just added following line
Session["L" + i + "ID"] = null;

remove
Values[i] = null;


这篇关于如何将会话变量数组的值无效为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆