Drop down lists selected index change event not firing

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 年 前
Hello there.........!!!

i have some problem regarding to "ddlAttributes" combo on productattribute.ascx user control...
What i m doing here is that i have created dynamic drop down named "ddlAttributes" on "ddlquantity" combo's selected index change event...
My second combo box in "ddlAttributes" is Magnetic stripe-- with values None with price 0 on index 0,Lo-co with price 20 on index 1 and Hi-co with price 30 on index 2..
Now i had to show all these values in labels in right portion of the user control...
so i took two functions named change and magstrip--

ddlAttributes.SelectedIndexChanged += new EventHandler(Change);
                                        ddlAttributes.AutoPostBack = true;
                                        ddlAttributes.Load += new EventHandler(magstrip);


now bydefault value of magnetic stripe's combo is None with price 0
when i select lo-co or hi-co
ddlAttributes.SelectedIndexChanged += new EventHandler(Change); this event fires
and it goes to change function but after selecting any  lo-co or hi-co value when i immediately select None

ddlAttributes.SelectedIndexChanged += new EventHandler(Change); this event fires
but it doesn't go to change function....

i have done ddlAttributes.SelectedIndex = -1... bt though i tried this it didn't work

Will you please help me by solving this problem...
Thank you
13 年 前
The problem as you've described is hard to follow... could you post some code?
13 年 前
Yes Off course it is


protected void Change(object sender, EventArgs e)
        {

            DropDownList clickedButton = (DropDownList)sender;
            
            //RegexOptions regopt = RegexOptions.None;

            //var regex = new Regex(@"\s+",regopt);
            //string tetst = regex.Replace(clickedButton.SelectedItem.Text, @"").ToLower();

            // Dictionary for Magnetic Strip //

            Dictionary<int, string> SecControls = new Dictionary<int, string>();
            SecControls.Add(1, "20 Mil");
            SecControls.Add(2, "20 MIL");
            SecControls.Add(3, "20 mil");
            SecControls.Add(4, "20ml");
            SecControls.Add(5, "20ML");
            SecControls.Add(6, "20Ml");
            SecControls.Add(7, "20Mil");
            SecControls.Add(8, "20mil");
            SecControls.Add(9, "20MIL");
            SecControls.Add(10, "20 Ml");
            SecControls.Add(11, "20 ML");
            SecControls.Add(12, "20 ml");
            SecControls.Add(13, "20 mL");
            SecControls.Add(14, "20mL");
            SecControls.Add(15, "20 MiL");
            SecControls.Add(16, "20 mIL");
            SecControls.Add(17, "20 mIl");
            SecControls.Add(18, "20 miL");
            SecControls.Add(19, "20MiL");
            SecControls.Add(20, "20mIL");
            SecControls.Add(21, "20mIl");
            SecControls.Add(22, "20miL");
            SecControls.Add(23, "20 MIl");
            SecControls.Add(24, "5 Mil");

            for (int z = 1; z <= SecControls.Count; z++)
            {
                if (clickedButton.NamingContainer.FindControl("13") != null)
                {
                    if (clickedButton.SelectedItem.Text.Length >= 2)
                    {
                        if (clickedButton.SelectedItem.Text.Length >= SecControls[z].Length && clickedButton.SelectedItem.Text.Substring(0, 6) != "30 Mil")
                        {
                            if (clickedButton.SelectedItem.Text.Substring(0, SecControls[z].Length) == SecControls[z].ToString())
                            {
                                if (clickedButton.NamingContainer.FindControl("14") != null)
                                {
                                    clickedButton.NamingContainer.FindControl("14").Visible = false;
                                    clickedButton.NamingContainer.FindControl("lbl14").Visible = false;
                                    clickedButton.NamingContainer.FindControl("15").Visible = false;
                                    clickedButton.NamingContainer.FindControl("lbl15").Visible = false;
                                    break;
                                }

                            }
                        }
                        else
                        {
                            DropDownList tempDlist = (DropDownList)clickedButton.NamingContainer.FindControl("13");
                            if (clickedButton.SelectedItem.Text != "5 Mil")
                            {
                                if (tempDlist.SelectedItem.Text.Substring(0, 6) == "30 Mil")
                                {
                                    if (clickedButton.NamingContainer.FindControl("14") != null)
                                    {
                                        clickedButton.NamingContainer.FindControl("14").Visible = true;
                                        clickedButton.NamingContainer.FindControl("lbl14").Visible = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }


                if (clickedButton.SelectedItem.Text.Length < 4)
                {
                    if (clickedButton.NamingContainer.FindControl("14") != null)
                    {
                        clickedButton.NamingContainer.FindControl("14").Visible = false;
                        clickedButton.NamingContainer.FindControl("lbl14").Visible = false;
                        clickedButton.NamingContainer.FindControl("15").Visible = false;
                        clickedButton.NamingContainer.FindControl("lbl15").Visible = false;
                    }
                }

            }



            // dictionary for variable data //

            Dictionary<int, string> sequentialcontrol = new Dictionary<int, string>();
            sequentialcontrol.Add(1, "Sequential");
            sequentialcontrol.Add(2, "sequential");
            sequentialcontrol.Add(3, "SEQUENTIAL");

            for (int f = 1; f <= sequentialcontrol.Count; f++)
            {
                if (clickedButton.SelectedItem.Text.Length >= 10)
                {
                    if (clickedButton.SelectedItem.Text.Substring(0, sequentialcontrol[f].Length) == sequentialcontrol[f].ToString())
                    {
                        if (clickedButton.NamingContainer.FindControl("24") != null)
                        {
                            clickedButton.NamingContainer.FindControl("24").Visible = true;
                            clickedButton.NamingContainer.FindControl("lbl24").Visible = true;
                            break;
                        }
                    }
                }
            }

            if (clickedButton.SelectedItem.Text.Length < 10)
            {
                if (clickedButton.NamingContainer.FindControl("24") != null)
                {
                    clickedButton.NamingContainer.FindControl("24").Visible = false;
                    clickedButton.NamingContainer.FindControl("lbl24").Visible = false;
                }
            }

            // dictionary for variable data //

            // dictionary for Encoding //

            Dictionary<int, string> encodingcontrol = new Dictionary<int, string>();

            encodingcontrol.Add(1, "No");
            encodingcontrol.Add(2, "None");
            encodingcontrol.Add(3, "Lo-Co Mag Stripe");
            encodingcontrol.Add(4, "lo-co Mag Stripe");
            encodingcontrol.Add(5, "Lo-Co Mag");
            encodingcontrol.Add(6, "Lo-co Mag");
            encodingcontrol.Add(7, "lo-co Mag");
            encodingcontrol.Add(8, "Hi-Co Mag Stripe");
            encodingcontrol.Add(9, "Hi-co Mag Stripe");
            encodingcontrol.Add(10, "hi-co Mag Stripe");
            encodingcontrol.Add(11, "Hi-Co Mag");
            encodingcontrol.Add(12, "Hi-co Mag");
            encodingcontrol.Add(13, "hi-co Mag");
            encodingcontrol.Add(14, "Lo-co Mag Stripe");
            encodingcontrol.Add(15, "Yes");
            encodingcontrol.Add(16, "yes");

            for (int g = 1; g <= encodingcontrol.Count; g++)
            {
                if (clickedButton.NamingContainer.FindControl("14") != null || clickedButton.NamingContainer.FindControl("15") != null || clickedButton.NamingContainer.FindControl("24") != null)
                {
                    if (clickedButton.SelectedItem.Text.Length >= 1)
                    {
                        if (clickedButton.SelectedItem.Text.Length >= encodingcontrol[g].Length)
                        {
                            if (clickedButton.SelectedItem.Text.Substring(0, encodingcontrol[g].Length) == encodingcontrol[g].ToString())
                            {
                                if (clickedButton.NamingContainer.FindControl("15") != null)
                                {
                                    clickedButton.NamingContainer.FindControl("15").Visible = true;
                                    clickedButton.NamingContainer.FindControl("lbl15").Visible = true;
                                    break;
                                }
                            }
                        }
                        else if (clickedButton.SelectedItem.Text.Substring(0, 3) == "Yes" || clickedButton.SelectedItem.Text.Substring(0, 3) == "yes")
                        {
                            if (clickedButton.NamingContainer.FindControl("15") != null)
                            {
                                clickedButton.NamingContainer.FindControl("15").Visible = false;
                                clickedButton.NamingContainer.FindControl("lbl15").Visible = false;
                                break;
                            }
                        }
                        else if (clickedButton.SelectedItem.Text.Substring(0, 6) != "30 Mil")
                        {
                            if (clickedButton.SelectedItem.Text.Substring(0, 6) == "20 Mil" || clickedButton.SelectedItem.Text.Substring(0, 16) == "Lo-Co Mag Stripe")
                            {
                                if (clickedButton.NamingContainer.FindControl("15") != null)
                                {
                                    clickedButton.NamingContainer.FindControl("15").Visible = false;
                                    clickedButton.NamingContainer.FindControl("lbl15").Visible = false;
                                    break;
                                }
                            }
                        }

                        else if (clickedButton.SelectedItem.Text.Substring(0, 6) != "30 Mil")
                        {
                            if (clickedButton.SelectedItem.Text.Substring(0, 6) == "20 Mil" || clickedButton.SelectedItem.Text.Substring(0, 16) == "Hi-Co Mag Stripe")
                            {
                                if (clickedButton.NamingContainer.FindControl("15") != null)
                                {
                                    clickedButton.NamingContainer.FindControl("15").Visible = false;
                                    clickedButton.NamingContainer.FindControl("lbl15").Visible = false;
                                    break;
                                }
                            }
                        }



                    }
                }
            }

            // end of dictionary

            phnameAttributes.Visible = false;
            phlabelAttributes.Visible = false;
            phvalueAttributes.Visible = false;
            phmylabelAttributes.Controls.Clear();
            phmynameAttributes.Controls.Clear();
            phmyvalueAttributes.Controls.Clear();

            AttriburetotalChange.Text = "";
            FinalPriceChange.Text = "";
            Afterchange.Clear();
            newarraylist.Clear();
            AttributePirceChange.Clear();

            //string selectedAttributes = string.Empty;
            var productVariantAttributes1 = ProductAttributeManager.GetProductVariantAttributesByProductVariantId(this.ProductVariantId);
            foreach (ProductVariantAttribute attribute in productVariantAttributes1)
            {
                //string controlId = string.Format("{0}_{1}", attribute.ProductAttribute.ProductAttributeId, attribute.ProductVariantAttributeId);
                string controlId = string.Format("{0}", attribute.ProductAttribute.ProductAttributeId);
                switch (attribute.AttributeControlType)
                {
                    case AttributeControlTypeEnum.DropdownList:
                        {

                            var ddlAttributes = phAttributes.FindControl(controlId) as DropDownList;
                            if (ddlAttributes != null)
                            {
                                int selectedAttributeId = 0;
                                if (!String.IsNullOrEmpty(ddlAttributes.SelectedValue))
                                {
                                    selectedAttributeId = int.Parse(ddlAttributes.SelectedValue);
                                }

                                if (selectedAttributeId > 0)
                                {
                                        Afterchange.Add(selectedAttributeId);
                                        Hashtable ht = new Hashtable();
                                        foreach (int item in Afterchange)
                                        {
                                            ht[item] = null;
                                            newarraylist = new ArrayList(ht.Keys);
                                        }  
                                }
                            }
                        }

                        break;
                    default:
                    break;                  
                }

            } // end of foreach loop


            ViewState["tmpPriceTotal"] = 0;

            //code for pring
            for (int op = 0; op < newarraylist.Count; op++)
            {
                DataTable x = ProductManager.GetProductAttributes(Convert.ToInt32(Afterchange[op]), q);


                for (int i = 0; i < x.Rows.Count - 1; i++)
                {

                    Label mynewlabel = new Label();

                    Label mythisnewlabel = new Label();
                    mythisnewlabel.Style.Add("align", "right");

                    Label mythatnewlabel = new Label();

                    var tmp_arr = x.Rows[i].ItemArray[0].ToString();
                    var tmp_arr1 = x.Rows[i].ItemArray[1].ToString();
                    var tmp_arr2 = x.Rows[i].ItemArray[2].ToString();

                    ViewState["tmpPriceTotal"] = Convert.ToDecimal(ViewState["tmpPriceTotal"]) + Convert.ToDecimal(tmp_arr1);

                    mynewlabel.ID = "rcol1" + x.Rows[i].ItemArray[3].ToString();
                    mythatnewlabel.ID = "rcol2" + x.Rows[i].ItemArray[3].ToString();
                    mythisnewlabel.ID = "rcol3" + x.Rows[i].ItemArray[3].ToString();

                   // Session["encoding"] = "0";

                    if (x.Rows[i].ItemArray[2].ToString().Trim() == "Encoding" || x.Rows[i].ItemArray[2].ToString().Trim() == "Scratch Off Panel")
                    {
                        Session["encoding"] = "1";
                    }
                    else if (x.Rows[i].ItemArray[2].ToString().Trim() == "Encoding" && x.Rows[i].ItemArray[2].ToString().Trim() == "Scratch Off Panel")
                    {
                        Session["encoding"] = "1";
                    }
                  

                    if (tmp_arr3.ContainsKey(mythisnewlabel.ID))
                    {
                        tmp_arr3.Remove(mythisnewlabel.ID);
                        tmp_arr3.Add(mythisnewlabel.ID, Convert.ToDecimal(tmp_arr1));
                    }
                    else
                    {
                        tmp_arr3.Add(mythisnewlabel.ID, Convert.ToDecimal(tmp_arr1));
                    }
                    //tmp_arr3.Add(tmp_arr1);

                    if (tmp_arr.Length > 1 && tmp_arr1.Length > 1 && tmp_arr2.Length > 1)
                    {
                      
                            string aprice = PriceHelper.FormatPrice(Convert.ToDecimal(tmp_arr1));
                            AttributePirceChange.Add(tmp_arr1);

                            // mythisnewlabel.Text = tmp_arr1;
                            if (aprice == "$0.00")
                            {
                                mynewlabel.Style.Add("display", "block");
                                mynewlabel.Style.Add("clear", "both");
                                mythisnewlabel.Style.Add("display", "block");
                                mythisnewlabel.Style.Add("clear", "both");
                                mythatnewlabel.Style.Add("display", "block");
                                mythatnewlabel.Style.Add("clear", "both");
                            }
                            else
                            {
                                mynewlabel.Text = tmp_arr;
                                mythisnewlabel.Text = aprice;
                                mythatnewlabel.Text = tmp_arr2;

                            }

                        }
                        else
                        {
                            mynewlabel.Text = "";
                            mythatnewlabel.Text = "";
                            mythisnewlabel.Text = "";
                        }
                    
                    
                    mynewlabel.Style.Add("display", "block");
                    mynewlabel.Style.Add("clear", "both");
                    mythisnewlabel.Style.Add("display", "block");
                    mythisnewlabel.Style.Add("clear", "both");
                    mythatnewlabel.Style.Add("display", "block");
                    mythatnewlabel.Style.Add("clear", "both");
                    mythatnewlabel.Style.Add("margin-left","-5px");

                    phmynameAttributes.Controls.Add(mythatnewlabel);
                    phmylabelAttributes.Controls.Add(mynewlabel);
                    phmyvalueAttributes.Controls.Add(mythisnewlabel);
                }
                
            }


            // Change By dipesh on 3-1-2011

            

            //
            if (clickedButton.NamingContainer.FindControl("13") != null)
            {
                if (clickedButton.SelectedItem.Text != "No")
                {
                    if (clickedButton.SelectedItem.Text != "None")
                    {
                        if (clickedButton.SelectedItem.Text.Substring(0, 6) == "20 Mil")
                        {
                            DropDownList tempDlist = (DropDownList)clickedButton.NamingContainer.FindControl("14");
                            if (tempDlist != null)
                            {
                                if (tempDlist.SelectedItem.Text != "None")
                                {
                                    if (tempDlist.SelectedItem.Text.Substring(0, 16) == "Lo-Co Mag Stripe" || tempDlist.SelectedItem.Text.Substring(0, 16) == "Hi-Co Mag Stripe")
                                    {
                                        clickedButton.NamingContainer.FindControl("rcol114").Visible = false;
                                        clickedButton.NamingContainer.FindControl("rcol214").Visible = false;
                                        clickedButton.NamingContainer.FindControl("rcol314").Visible = false;
                                        clickedButton.NamingContainer.FindControl("rcol115").Visible = false;
                                        clickedButton.NamingContainer.FindControl("rcol215").Visible = false;
                                        clickedButton.NamingContainer.FindControl("rcol315").Visible = false;
                                    }
                                    else
                                    {
                                        clickedButton.NamingContainer.FindControl("rcol114").Visible = true;
                                        clickedButton.NamingContainer.FindControl("rcol214").Visible = true;
                                        clickedButton.NamingContainer.FindControl("rcol314").Visible = true;
                                    }
                                }
                            }
                        }
                    }
                }
                if (clickedButton.NamingContainer.FindControl("14") != null || clickedButton.NamingContainer.FindControl("15") != null)
                {
                    if (clickedButton.SelectedItem.Text != "None")
                    {
                        if (clickedButton.SelectedItem.Text != "No")
                        {
                            if (clickedButton.SelectedItem.Text.Substring(0, 3) == "Yes")
                            {
                                DropDownList tempDlist = (DropDownList)clickedButton.NamingContainer.FindControl("13");

                                if (tempDlist.SelectedItem.Text.Substring(0, 6) == "20 Mil")
                                {
                                    clickedButton.NamingContainer.FindControl("rcol114").Visible = true;
                                    clickedButton.NamingContainer.FindControl("rcol214").Visible = true;
                                    clickedButton.NamingContainer.FindControl("rcol314").Visible = true;
                                    clickedButton.NamingContainer.FindControl("rcol115").Visible = true;
                                    clickedButton.NamingContainer.FindControl("rcol215").Visible = true;
                                    clickedButton.NamingContainer.FindControl("rcol315").Visible = true;
                                }

                            }


                            else if (clickedButton.SelectedItem.Text.Substring(0, 6) != "30 Mil")
                            {
                                if (clickedButton.SelectedItem.Text.Substring(0, 16) == "Lo-Co Mag Stripe" || clickedButton.SelectedItem.Text.Substring(0, 16) == "Hi-Co Mag Stripe")
                                {
                                    DropDownList tempDlist = (DropDownList)clickedButton.NamingContainer.FindControl("13");

                                    if (tempDlist.SelectedItem.Text.Substring(0, 6) == "20 Mil")
                                    {
                                        clickedButton.NamingContainer.FindControl("rcol114").Visible = false;
                                        clickedButton.NamingContainer.FindControl("rcol214").Visible = false;
                                        clickedButton.NamingContainer.FindControl("rcol314").Visible = false;
                                        clickedButton.NamingContainer.FindControl("rcol115").Visible = false;
                                        clickedButton.NamingContainer.FindControl("rcol215").Visible = false;
                                        clickedButton.NamingContainer.FindControl("rcol315").Visible = false;
                                    }
                                }

                            }
                        }
                    }
                }


                if (clickedButton.SelectedItem.Text != "No")
                {
                    if (clickedButton.SelectedItem.Text != "None")
                    {
                        if (clickedButton.SelectedItem.Text.Substring(0, 6) == "Random")
                        {
                            DropDownList tempDlist = (DropDownList)clickedButton.NamingContainer.FindControl("24");
                            if (tempDlist.SelectedItem.Text != "No")
                            {
                                if (tempDlist.SelectedItem.Text.Substring(0, 3) == "Yes")
                                {
                                    clickedButton.NamingContainer.FindControl("rcol124").Visible = false;
                                    clickedButton.NamingContainer.FindControl("rcol224").Visible = false;
                                    clickedButton.NamingContainer.FindControl("rcol324").Visible = false;
                                }
                                else
                                {
                                    clickedButton.NamingContainer.FindControl("rcol124").Visible = true;
                                    clickedButton.NamingContainer.FindControl("rcol224").Visible = true;
                                    clickedButton.NamingContainer.FindControl("rcol324").Visible = true;
                                }
                            }

                        }
                    }

                    if (clickedButton.SelectedItem.Text.Substring(0, 3) == "Yes")
                    {
                        DropDownList tempDlist = (DropDownList)clickedButton.NamingContainer.FindControl("20");

                        if (tempDlist.SelectedItem.Text.Substring(0, 6) == "Random")
                        {
                            clickedButton.NamingContainer.FindControl("rcol124").Visible = false;
                            clickedButton.NamingContainer.FindControl("rcol224").Visible = false;
                            clickedButton.NamingContainer.FindControl("rcol324").Visible = false;

                        }

                    }
                }
            }

            //Calculation of Attribute price

            
            //newarraylist.Clear();
            //AttributePirceChange.Clear();

            // end of calculation of Attribute Price

decimal totalchange = 0;        
    foreach (KeyValuePair<string
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.