Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
520
Webdropdown question cascading dropdown: Keep Selection
posted

I hope this question is not misplaced, i could not find the approperiate webdropdown related forum. 

I have two Webdropdowns, both habe mutiselect enabled. Logically the first dropdown represents machines, the second represents products they produce. Once a machine is selected, the second dropdown is populated with available products for the selected machines.

The following Code is used to enable a cascading for the second dropdown (both dropdowns are in an update panel):


protected void WebDropDown1_ValueChanged(object sender, Infragistics.Web.UI.ListControls.DropDownValueChangedEventArgs e)
{
DataTable datatable = new DataTable();
int i;
DataTable dt = new DataTable("TestTabel");
dt.Columns.Add("Maschine", typeof(string));

for (i = 0; i < WebDropDown1.SelectedItems.Count; i++)
{
dt.Rows.Add(WebDropDown1.SelectedItems[i].Value.ToString());
}
string cs = string.Empty;

cs = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

SqlConnection con = new SqlConnection(cs);

con.Open();
SqlCommand cmd = new SqlCommand("CascadingPartNumber", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter tblvaluetype = cmd.Parameters.AddWithValue("@List", dt); //Passing table value parameter
SqlParameter Beginn = cmd.Parameters.AddWithValue("Begin", WebDatePicker1.Value);
SqlParameter Ende = cmd.Parameters.AddWithValue("End", WebDatePicker2.Value);
tblvaluetype.SqlDbType = SqlDbType.Structured; // This is used to tell ADO.NET we are passing Table value Parameter

SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
this.WebDropDown2.DataSource = ds;
this.WebDropDown2.DataBind();

The Code works. However if a new item is selected from the first dropdown, additionally to the ones seleted before, the second webdropdown is databound again and the previous collection is lost, which seems strange to the enduser.

Hence the functionality i need is keeping the selection of the second dropdown if the items of webdropdown 1 are still selected.