ラベル dropdown の投稿を表示しています。 すべての投稿を表示
ラベル dropdown の投稿を表示しています。 すべての投稿を表示

2012年3月28日水曜日

Reset Cascading Dropdown

I have a set of cascading dropdowns that I need to be able to programatically reset via javascript. I can change the selectedIndexes but that doesn't change any of the data "behind the scenes".

Thanks

Hi

Doesn't change any of the data "behind the scenes", What you mean?

Would you please post some code,so I can reproduce the problem and resolve it more quickly?

Thanks


As I have seen it for three cascading drop downs there are also three hidden form fields that contain data. My specific scenario was modifing some existing code that utilized three drop downs. The application was a store selector. The user could type in a postal code or use drop downs (Country, Region, City). I needed to reset the drop downs if a user types in a postal code. Setting up the blur event on the postal code text box was simple enough. But getting the drop-downs to reset was more challenging. I originally trimmed the item list down to the first item (please select). However on postback the original drop down selections came back. What I ended up doing was triming the item list and resetting the "hidden" fields to ":::" which is what the starting state appears to be.

There has to be an easier way to reset the drop downs to thier default state (via javascript). If the user simply sets the first drop down to the 0 index all drop downs reset. However, using using JS to set the selectedIndex property doesn't cause the client side event to fire.

Hopefully that helps a little. I am probably just missing something obvious. Is the client side JS code documented anywhere?

2012年3月24日土曜日

Root of Cascading Dropdowns Needs a Parameter. How do I do this?

I have a page with a dropdown called ddlYourTeams that is populated based on a single parameter, intUserID. If I don't cascade, I can populate this ddl with a SQL datasource that takes the intUserID parameter from a Session variable. I would like to make it the parent of two other dropdowns, ddlOpponents and ddlHomeFacilities. ddlOpponents would in turn be the parent of a fourth dropdown, ddlAwayFacilities. Each dropdown would have its corresponding Cascading Extender (CE). My problem is how to pass intUserID to the first webservice to get things going.

I thought of adding a parameter to the parent web service. But I believe this cannot be done as the CE's expect a fixed signature. Also I can't add a parameter because I can't access the point where it's invoked and so cannot set the parameter value.

In the context of the make-model-color example, I need to have the controls read a subset of makes from a ManufacturerID stored in session. So makes should be just GM makes, not all makes based on an external parameter.

How can I do this?

Thanks in advance for any assistance.

Hi,

You can append a parameter named contextKey to the webmethod.

For instance:

public static AjaxControlToolkit.CascadingDropDownNameValue[]
GetDropDownContentsPageMethod(string knownCategoryValues, string category, string contextKey)


CascadingDropDown2.ContextKey = "contextKeyOf2"; // this line set the value of the contextKey parameter


Raymond,

Thank you for your answer. Unfortunately, I was unable to get the suggestion to work. As this question is probably of interest to others as well, I wonder if you could upload a little example showing how to use the parameter.

I keep getting the error: 'AjaxControlToolkit.CascadingDropDown' does not contain a definition for 'ContextKey'

Thanks,

Jeff


Jeff,

Which version of Toolkit are you using? Can you update to the latest one and try again?


Another tip, session can be accessed from web service too. Please refer to this documentation: http://msdn2.microsoft.com/en-us/library/aa480509.aspx


And here is a sample make use of ContextKey.

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { CascadingDropDown1.ContextKey = "contextKeyOf1"; CascadingDropDown2.ContextKey = "contextKeyOf2"; CascadingDropDown3.ContextKey = "contextKeyOf3"; } [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 = contextKey + i.ToString(); result[i].value = contextKey + i.ToString(); } return result; }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head id="Head1" runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true" /> <asp:DropDownList ID="DropDownList1" runat="server" > </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server"> </asp:DropDownList> <asp:DropDownList ID="DropDownList3" runat="server" > </asp:DropDownList> <ajaxToolkit:CascadingDropDown ID="CascadingDropDown1" BehaviorID="cdd1" ServiceMethod="GetDropDownContentsPageMethod" Category="ca1" runat="server" PromptText="Please select a make" TargetControlID="DropDownList1"> </ajaxToolkit:CascadingDropDown> <ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" ServiceMethod="GetDropDownContentsPageMethod" Category="ca2" BehaviorID="cdd2" ParentControlID="DropDownList1" PromptText="Please select a make" runat="server" TargetControlID="DropDownList2"> </ajaxToolkit:CascadingDropDown> <ajaxToolkit:CascadingDropDown ID="CascadingDropDown3" ServiceMethod="GetDropDownContentsPageMethod" Category="ca3" BehaviorID="cdd3" ParentControlID="DropDownList2" PromptText="Please select a make" runat="server" TargetControlID="DropDownList3"> </ajaxToolkit:CascadingDropDown> </div> </form></body></html>

I had been using 10201, which seems about 4 versions back. I have downloaded 10920 and will re-try your suggestion. Thanks again.