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
string _L1, _L2, _L3, _L4, _L5;
string[] Values;
_L1 = _L2 = _L3 = _L4 = _L5 = null;
public void HideRemainingDDLs(DropDownList _ddlname)
{
_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 };
if (up.HasControls())
{
foreach (Control subCtrl in up.Controls[0].Controls)
{
if (subCtrl is DropDownList)
{
DropDownList ddl = subCtrl as DropDownList;
if (ddl.Visible == true)
{
if (ddl != null && ddl.TabIndex > _ddlname.TabIndex)
{
int i = ddl.TabIndex;
Values[i] = null;
ddl.Visible = false;
ddl.Items.Clear();
}
}
}
}
}
}
Example DDL SelectedIndexChanged Event
protected void DDLSubL1_SelectedIndexChanged(object sender, EventArgs e)
{
if (populate("PopulateL2Subjects", DDLSubL2, DDLSubL1, out _subject1))
{
DDLSubL2.Visible = true;
}
else
{
HideRemainingDDLs(DDLSubL1);
DDLSubL2.Items.Add("Select chapter");
}
Session["L1ID"]= _subject1;
}