Monday, March 26, 2012

CascadingDropDownProperties - Setting SelectedValue dynamically

I have an application where I am using the CascadingDropDown Lists. I have incorporated a set of them into a control.

I want to add a property to my CascadingDropDownProperties that will set an initial "filter" for my list.

For example, if I were using the sample CDD provided on the website that gives Make, Model, Color in my application, I may want to tell my control to only select foreign or domestic makes. At this point, the control can continue on to do what it needs to.

My web method is calling a MS-SQL stored procedure, and it has an input parameter of foreign/domestic (CarClass) for selecting the available Makes.

My questions on this are as follows:

    How do I set up my CascadingdropDownProperties to add the Foreign/Domestic (CarClass) value?

    How do I set this value in the code-behind?

(I will omit my actual DropDownLists from my code.)

Here is my CascadingDropDown definition:

1 <atlasToolkit:CascadingDropDown ID="CascadingDropDown1" runat="server">
2 <atlasToolkit:CascadingDropDownProperties
3 Category="CarClass"
4 ServicePath="~/wsSelectCar_Data.asmx" />
5
6 <atlasToolkit:CascadingDropDownProperties
7 TargetControlID="ddlMake"
8 Category="Make"
9 PromptText="Please select a Make"
10 ServiceMethod="GetMakes"
11 ServicePath="~/wsSelectCar_Data.asmx" />
12
13 <atlasToolkit:CascadingDropDownProperties
14 TargetControlID="ddlModel"
15 ParentControlID="ddlMake"
16 Category="Model"
17 PromptText="Please select a Model"
18 ServiceMethod="GetModel"
19 ServicePath="~/wsSelectCar_Data.asmx" />
20
21 <atlasToolkit:CascadingDropDownProperties
22 TargetControlID="ddlColor"
23 ParentControlID="ddlMake"
24 Category="Color"
25 PromptText="Please select a Color"
26 ServiceMethod="GetColor"
27 ServicePath="~/wsSelectCar_Data.asmx" />
28 </atlasToolkit:CascadingDropDown>

As you can see, I tried to create a property with the Category "CarClass". My Code-behind has the following to try to set the value:

1 int intCarClass =int.Parse(Session["CarClass"].ToString());
2 this.CascadingDropDown1.TargetProperties[0].SelectedValue = intCarClass.ToString();

This does not seem to work.

Thanks,
Bryan

Hi Bryan,

I'd recommend you switch to a page method and then just check whether or not you should apply the additional filter however you want.

Thanks,
Ted

Can you provide sample code for doing this?

I am not familiar with the "Page" methods.

Thanks.

No comments:

Post a Comment