DropDownList selection oddity
-
I'm making an ASP webpage using VB.NET. I'm creating controls on the fly. When I create my dropdownlists on the fly I am getting an odd behavior. When I change the selected value of one of the controls in the array it changes it for all of them. I'm currently filling an array of listitems from a database and then using AddRange to add the values to each dropdownlist. When I attempt to use the SelectedValue property of the dropdownlist to set which value is selected, it effects all of the dropdown lists. I can tell this because every drop down list is set the value the last item should have. This is the loop I use to fill the listitem array (it's redim-ed to the proper size) ctr = 0 For Each drddlFill In ds.Tables("dtEmps").Rows lsiUpline(ctr) = New System.Web.UI.WebControls.ListItem lsiUpline(ctr).Text = drddlFill("employee_id") & " - " & drddlFill("first_name") & " " & drddlFill("last_name") lsiUpline(ctr).Value = drddlFill("employee_id") ctr += 1 Next Next I fill each drop down list Row = new TableRow Cell = new TablecCell ddlUpline_Array(ctr).Items.AddRange(lsiUpline) ddlUpline_Array(ctr).SelectedValue = databaseInfo("ID") Cell.Controls.Add(ddlUpline_Array(ctr)) Row.Cells.Add(Cell) tblBaseshop.Rows.Add(Row) databaseInfo is pulling correct information. The rest of the row is filled with information from this so I know it is different for each row. Every dropdownlist in ddlUpline_Array gets set to the selection of the last it. Any advice on how to get each ddl set to a different selection? If I do a loop and fill each box from the database each time, the selection will be different for each box, but that is much too time consuming. Thanks The wisest of the wise may err. - Aeschylus