Wednesday, March 21, 2012

Default value in child CascadingDropDown

I'm using the standard technique for setting the default option in the Web service: result.Add(newCascadingDropDownNameValue(name, code, BLOCKED EXPRESSION

(expression is true only for the default option)

This technique ony works for the parent list, and doesn't do anything for the child list. In other words, when the selection on the parent list changes, and the child list gets populated via its Web service, setting the default option via the above technique doesn't actually do anything (the first option of the child element is always selected by default). What am I doing wrong?

Hi Tomers,

My understanding of your case is that you want to set a default value for DropDownList ,which is associated with a CascadingDropDown.

As far as I know, the returned value will add to it's child list instead of parent list. Here is the code section in CascadingDropDownNameValue.cs.

public CascadingDropDownNameValue(string name, string value, bool defaultValue)
{
this.name = name;
this.value = value;
this.isDefaultValue = defaultValue;
}

I have made a sample and it works fine on my local machine. Please see my sample which is using oledb:

[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 myList =new List(); strSql ="SELECT * FROM tb_City WHERE StateID=" + stateID.ToString(); GetDr(strSql);while (myReader.Read()) {if (myReader["CityName"].ToString() =="Shanghai") { 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(); }

In your case, I think you should check your code and debug it step-by-step if necessary.

Best Regards,

Jonathan

No comments:

Post a Comment