I have created a panel as a place holder on an input interface and I want to be able to dynamicaly fill it with drop down lists, check boxes etc. So below I'll show you the two main pieces of this effort - the function that creates the dropdown list in question and the function that fires when the submit button is clicked.
I've stepped through this and what I'm finding is that when the submit button is clicked the page posts back and the dropdown list is removed from the page.
Expand|Select|Wrap|Line Numbers
- protected void lbNewShiftLog_Click(object sender, EventArgs e)
- {
- DropDownList ddlCusts = new DropDownList();
- //datasource is populating the dropdown list fine
- ddlCusts.DataSource = dS;
- ddlCusts.DataTextField = "customer";
- ddlCusts.DataValueField = "customer";
- ddlCusts.DataBind();
- ddlcusts.ID = "ddlcusts";
- pnlOptions.Controls.Add(ddlcusts);
- }
- protected void btnSubmit_Click(object sender, EventArgs e)
- {
- DropDownList ddl = (DropDownList)pnlOptions.FindControl("ddlCusts");
- if (ddl != null)
- {
- Label1.Text = ddl.SelectedItem.ToString();
- }
- }
The above function returns null - I have also tried
Expand|Select|Wrap|Line Numbers
- DropDownList ddl = (DropDownList)PreviousPage.FindControl("ddlCusts");
Object reference not set to an instance of an object.
Plz Healp
Thank You