How to eliminate one of my extra DropDownLists in C#?
Posted
by salvationishere
on Stack Overflow
See other posts from Stack Overflow
or by salvationishere
Published on 2010-04-10T11:44:41Z
Indexed on
2010/04/10
11:53 UTC
Read the original article
Hit count: 554
I'm developing a C#/SQL web app in VS 2008 but for some reason I have one extra DropDownList. The very first dropdownlist displaying is empty. Can you help me identify the cause of this behavior? I'm baffled!
An excerpt of my code is below.
private DropDownList[] newcol;
// Add DropDownList Control to Placeholder
private DropDownList[] CreateDropDownLists()
{
DropDownList[] dropDowns = new DropDownList[NumberOfControls];
for (int counter = 0; counter < NumberOfControls; counter++)
{
DropDownList ddl = new DropDownList();
SqlDataReader dr2 = ADONET_methods.DisplayTableColumns(targettable);
ddl.ID = "DropDownListID" + counter.ToString();
int NumControls = targettable.Length;
DataTable dt = new DataTable();
dt.Load(dr2);
ddl.DataValueField = "COLUMN_NAME";
ddl.DataTextField = "COLUMN_NAME";
ddl.DataSource = dt;
ddl.SelectedIndexChanged += new EventHandler(ddlList_SelectedIndexChanged);
ddl.DataBind();
ddl.AutoPostBack = true;
ddl.EnableViewState = true; //Preserves View State info on Postbacks
//ddlList.Style["position"] = "absolute";
//ddl.Style["top"] = 80 + "px";
//ddl.Style["left"] = 0 + "px";
dr2.Close();
dropDowns[counter] = ddl;
}
return dropDowns;
}
protected void ddlList_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
string ID = ddl.ID;
}
//Create display panel
private void CreateDisplayPanel()
{
btnSubmit.Style.Add("top", "auto");
btnSubmit.Style.Add("left", "auto");
btnSubmit.Style.Add("position", "absolute");
newcol = CreateDropDownLists();
for (int counter = 0; counter < NumberOfControls; counter++)
{
pnlDisplayData.Controls.Add(newcol[counter]);
pnlDisplayData.Controls.Add(new LiteralControl("<br><br><br>"));
pnlDisplayData.Visible = true;
pnlDisplayData.FindControl(newcol[counter].ID);
}
}
© Stack Overflow or respective owner