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.
0 件のコメント:
コメントを投稿