locked
When do I set the value of a cascading drop down with an existing value? RRS feed

  • Question

  • User-1423890915 posted

    I have gotten cascading drop downs to work on my page.   The do fine when i am creating a new record.

     My problem is how to handle them when the user wants to edit an existing record.  I need to set drop down to show the existing value, but I can't figure out when to do that.  My first attempt was to do it in page_load - but at that point the first drop down has not yet been populated.

     What is the event that fires the population of the first drop down?

    If i set the value of a cascading drop down in code, will that trigger the population of the dependent dropdown?

     Thanks,

    Kirk

    Thursday, December 6, 2007 9:34 PM

Answers

  • User-1087479560 posted

     Hi Kirk,

    You need to achieve that in the method that fills the DDL by setting an item's isDefault property to true. For instance:

    [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public static AjaxControlToolkit.CascadingDropDownNameValue[]
            GetDropDownContentsPageMethod(string knownCategoryValues, string category, string contextKey)
        {
            AjaxControlToolkit.CascadingDropDownNameValue[] result =
                new AjaxControlToolkit.CascadingDropDownNameValue[10];
            for (int i = 0; i < 10; i++)
            {
                result[i] = new AjaxControlToolkit.CascadingDropDownNameValue();
                result[i].name = i.ToString();
                result[i].value = i.ToString();
                if (result[i].value == "???") // any criterion here
                    result[i].isDefaultValue = true;
            }
            return result;
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 11, 2007 10:53 PM

All replies

  • User-1087479560 posted

     Hi Kirk,

    You need to achieve that in the method that fills the DDL by setting an item's isDefault property to true. For instance:

    [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public static AjaxControlToolkit.CascadingDropDownNameValue[]
            GetDropDownContentsPageMethod(string knownCategoryValues, string category, string contextKey)
        {
            AjaxControlToolkit.CascadingDropDownNameValue[] result =
                new AjaxControlToolkit.CascadingDropDownNameValue[10];
            for (int i = 0; i < 10; i++)
            {
                result[i] = new AjaxControlToolkit.CascadingDropDownNameValue();
                result[i].name = i.ToString();
                result[i].value = i.ToString();
                if (result[i].value == "???") // any criterion here
                    result[i].isDefaultValue = true;
            }
            return result;
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 11, 2007 10:53 PM
  • User-1423890915 posted

    Thank you!   That was exactly what I needed.

    I declard some public variables in my service, and i set the value of the variables in Page_Load.

    Then, as you suggest, In the loop that adds items to the list, I compare the value of each item against the value in the public variable.

    Woiks like a charm! :)

    Thanks again,

    Kirk 

     

     

    Thursday, December 20, 2007 8:27 PM