<div>
Make: <asp:DropDownList ID="ddlMake" runat="server"/><br/>
Model: <asp:DropDownList ID="ddlModel" runat="server"/><br/>
Color: <asp:DropDownList ID="ddlColor" runat="server"/>
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
</div>
<%@ Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="atlasToolkit" %>
<atlasToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server">
</atlasToolkit:CascadingDropDown>
[WebMethod]
public CascadingDropDownNameValue[] GetColorsForModel(string knownCategoryValues, string category) The knownCategoryValues parameter will return a string containing the currently selected category values, as well as the category to retrieve values for. For example, if the extender is populating the "Color" field, you will be passed the values for the "Make" and "Model" fields, as well as "Color" to specify the field to return values for.The CascadingDropDown class has a helper method for unpacking the category values:
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
This method will return a StringDictionary containing the name/value pairs of the currently selected values. So imagine you've got a database with tables for the Make (manufacturer), Model, and Color information, and you're accessing that database through a DataSet to which you've added methods for getting each set of values.The web method to get the available colors for a given model would look like this:
public CascadingDropDownNameValue[] GetColorsForModel(
string knownCategoryValues, string category) {
int modelId;
if (!kv.ContainsKey("Model") || !Int32.TryParse(kv["Model"], out modelId))
{
throw new ArgumentException("Couldn't find make.");
}
CarsTableAdapters.ColorTableAdapter adapter = new
CarsTableAdapters.ColorTableAdapter();
Cars.ColorDataTable colorTable = adapter.GetColorsForModel(modelId);
List<CascadingDropDownNameValue> values = new
List<CascadingDropDownNameValue>();
foreach (DataRow dr in colorTable) {
values.Add(
new CascadingDropDownNameValue(
(string)dr["Color"],
dr["ColorID"].ToString()));
return values.ToArray();
<atlasToolkit:CascadingDropDownProperties
TargetControlID="ddlMake"
Category="Make"
PromptText="Select a manufacturer"
ServicePath="CarsService.asmx"
ServiceMethod="GetCarMakes" />
TargetControlID="ddlModel"
ParentControlID="ddlMake"
PromptText="Please select a model"
ServiceMethod="GetModelsForMake"
Category="Model" />
TargetControlID="ddlColor"
ParentControlID="ddlModel"
PromptText="Please select a color"
ServiceMethod="GetColorsForModel"
Category="Color"/>
Finally, in order for the values to be submitted, EventValidation needs to be disabled for the page. EventValidation ensures that the values in each control match the values that were present when the page was rendered, but since these drop downs are populating on the client side, this is never true. We’re working on a way to resolve this issue (I'm not happy about it either!), but please ensure that you understand this and validate the data appropriately in your post back when using this control.
PingBack from http://lowcostcarinsurances.info/story.php?id=3766