Assigning value from dataset as selected value in cascading dropdowns

Last post 02-06-2008 1:42 AM by Jonathan Shen – MSFT. 1 replies.

Sort Posts:

  • Assigning value from dataset as selected value in cascading dropdowns

    01-31-2008, 12:55 PM
    • Member
      point Member
    • stormcandi
    • Member since 06-11-2007, 11:13 PM
    • Posts 17

    hello!  I have successfully implemented the Ajax Cascading Dropdowns but am running into an issue.  I am databinding the available selections to all three of my dropdown lists.  Then I need to make the selected value of each dropdown a value from my dataset.  The selected value works for the first dropdown, but I cannot figure out how to set up the selected values of the other 2 dropdowns.  (This would be values a user has selected previously, not default values.)

    Can anyone assist me?

    Thanks in advance!

     

  • Re: Assigning value from dataset as selected value in cascading dropdowns

    02-06-2008, 1:42 AM
    Answer

    Hi Stormcadi,

    As far as I know,  you should do some modifications on your WebService.You should add a  field to your tabel which get the datas from.  This field indicates that if it is the default selected item under some condition(Based on the former CascadingDropDown's selection).

        [WebMethod]
        public CascadingDropDownNameValue[] GetCities(string knownCategoryValues, string category)
        {
            StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
            int stateID;
            if (!kv.ContainsKey("State") || !Int32.TryParse(kv["State"], out stateID))
            {
                return null;
            }
            List<CascadingDropDownNameValue> myList = new List<CascadingDropDownNameValue>();
            strSql = "SELECT * FROM tb_City WHERE StateID=" + stateID.ToString();

            GetDr(strSql);
            while (myReader.Read())
            {
                if (myReader["isDefault"].ToString() =="true")
                {
                    myList.Add(new CascadingDropDownNameValue(myReader["CityName"].ToString(), myReader["CityID"].ToString(),true));
                }
                else {
                    myList.Add(new CascadingDropDownNameValue(myReader["CityName"].ToString(), myReader["CityID"].ToString(),false));
                }
            }
            myReader.Close();
            return myList.ToArray();
        }

    Please remove the CascadingDropDown's PromptText property. For example,

           <cc1:CascadingDropDown ID="CascadingDropDown2" BehaviorID="myCDECity" runat="server" TargetControlID="dlCity" ParentControlID="dlState"
                Category="City" ServicePath="../WebService/CityServiceOledb.asmx"
                ServiceMethod="GetCities" LoadingText="Load Text....">
            </cc1:CascadingDropDown>

    Best regards,

    Jonathan

    Jonathan Shen
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (2 items)