I guess my problem begs the question, how do I store a DropDownList (or other control in Application State and pull it out and reuse it? In my web application Global.asax.cs I am creating a DropDownList and throwing it into Application state, hoping to reuse it on this page (and wherever else). This code should dynamically create a table with 3 rows and a ddl0 for each. It only creates one DDL and displays it in the 3rd row, very strange.
Code:
protected override void OnInit(EventArgs e)
{
sSearchConditions = new string[] { "", "Begins With", "Contains", "Does Not Contain", "Ends With", "Equals", "Not Equal" };
base.OnInit(e);
Table tSearch = new Table();
tSearch.ID = "tCriteria";
TableHeaderRow thr = new TableHeaderRow();
for (int n = 0; n < 3; n++)
{
Label lblFields = new Label();
lblFields.Text = "Select Search Field:";
lblFields.CssClass = "tLBLText";
Label lblCondition = new Label();
lblCondition.Text = "Select Condition: ";
lblCondition.CssClass = "tLBLText";
Label lblValue = new Label();
lblValue.Text = "Type Value: ";
lblValue.CssClass = "tLBLText";
//Fields
DropDownList ddl0 = new DropDownList();
ddl0 = (DropDownList)Application[Global.DDLFields];
ddl0.ID = "ddlFields" + n.ToString();
//Conditions
DropDownList ddl1 = new DropDownList();
ddl1.ID = "ddlCondition" + n.ToString();
ddl1.DataSource = sSearchConditions;
ddl1.DataBind();
TextBox tb1 = new TextBox();
tb1.ID = "tb" + n.ToString();
tb1.CssClass = "tcText";
TableRow tr = new TableRow();
TableCell tc1 = new TableCell();
tc1.Controls.Add(lblFields);
tc1.Controls.Add(ddl0);
TableCell tc2 = new TableCell();
tc2.Controls.Add(lblCondition);
tc2.Controls.Add(ddl1);
TableCell tc3 = new TableCell();
tc3.Controls.Add(lblValue);
tc3.Controls.Add(tb1);
tr.Cells.Add(tc1);
tr.Cells.Add(tc2);
tr.Cells.Add(tc3);
tSearch.Rows.Add(tr);
}
pCustomSearch.Controls.Add(tSearch);
//pCustomSearch is a Panel Control
Comment