2014年7月13日 星期日

[RESOLVED] add dropdown and textboxes to a dictionary collection


Hello guys,


I am using the approach to be able to iterate through the textboxes and dropdow list on a page



public static IEnumerable GetAllControls(Control parent)
{
if(null == parent) return null;

return new Control[] { parent }.Union(parent.Controls.OfType().SelectMany(child => GetAllControls(child));
}



foreach(DropDownList list in GetAllControls(this).OfType())
{
//TODO: add values to dictionary collections and append to session object
}

Now, after the loop and getting the values, I need to be able to store the droplist list ids and values into a sesion to be available elsewhere in the application.


Please help.



Thanks



untested, but something like


Dictionary data = new Dictionary();

foreach(DropDownList list in GetAllControls(this).OfType())
{
data.Add (list.ID, list.Items);
}

Session["DropDownData"] = data;


沒有留言:

張貼留言