Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET session
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; 
} 
Posted 1-Nov-12 9:15am
Comments
Sergey Alexandrovich Kryukov at 1-Nov-12 15:02pm
   
Nullify to null is done in exact same way as unite to one. :-)
Jokes aside, what's the problem? How to assign indexed property (or anything) to null?
--SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Just added following line
Session["L" + i + "ID"] = null;
 
remove
Values[i] = null;
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 490
1 Maciej Los 305
2 Richard MacCutchan 270
3 Mathew Soji 220
4 BillWoodruff 210
0 OriginalGriff 8,834
1 Sergey Alexandrovich Kryukov 7,477
2 DamithSL 5,689
3 Maciej Los 5,329
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 5 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100