Navigation
Home
Documentation
Download
Forums
Samples
FAQ
Team
Support
Project
Bug Report
Feature Request
Submit Patch
Create a new Page
All Pages
Categories
Newest Pages
Recent Changes
Administration
File Management
Login/Logout
Language Selection
Your Profile
Create Account
Quick Search
Advanced Search »
Help Wanted!
If you are using .netTiers and find it as invaluable as we do, please consider giving back to the .netTiers team by helping with our effort to fully document .netTiers. To help, simply
create an account
and you will then be able to edit this wiki.
Back
History
AjaxControlToolkit CascadingDropDown
<nowiki></nowiki>This example shows how the AjaxControlToolkit CascadingDropDownExtender control can be used with .netTiers. This is a very simple example, but shows how to use this very nice control. First, here is the database schema: [imageauto|Database Schema|{UP}DocumentationImages%2fdbschema.png] The following code snippet shows the ASPX page. Again, it's very simple containing two drop down lists. When an item is selected from the first list, the items in the second list are changed accordingly. <code lang="XML" linenumbers="false"> <asp:ScriptManager ID="scriptmanager1" EnablePartialRendering="true" runat="Server" /> <div> <asp:DropDownList runat="server" id="dataLevel1" AppendDataBoundItems="true" EnableViewState="true" > <asp:ListItem Text="--All--" Value="" /> </asp:DropDownList> <ajaxToolkit:CascadingDropDown ID="ccdLevel1" runat="server" TargetControlID="dataLevel1" Category="Level1" PromptText="--All--" ServiceMethod="GetLevel1Data" /> <br /> <asp:DropDownList runat="server" id="dataLevel2" AppendDataBoundItems="true" DataValueField="Level2Id" DataTextField="Level2Name" EnableViewState="true"> <asp:ListItem Text="--All--" Value="" /> </asp:DropDownList> <ajaxToolkit:CascadingDropDown ID="ccdLevel2" runat="server" TargetControlID="dataLevel2" ParentControlID="dataLevel1" Category="Level2" PromptText="--All--" ServiceMethod="GetLevel2Data" LoadingText="Loading List..." /> </div> </form> </code> The last part to get this all working is the code-behind for the ASPX page show below. Note that the web page has the ScriptService attribute attached to it, and the methods that get called by the CascadingDropDown control have the WebMethod attribute. <code lang="C#" linenumbers="false"> using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using NetTiersTest.Entities; using NetTiersTest.Services; using AjaxControlToolkit; using System.Web.Services; using System.Collections.Specialized; using System.Collections.Generic; [System.Web.Script.Services.ScriptService()] public partial class CascadingDropDownSample : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } [WebMethod] public static AjaxControlToolkit.CascadingDropDownNameValue[] GetLevel1Data(string knownCategoryValues, string category) { StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); CDD_Level1Service service = new CDD_Level1Service(); TList<CDD_Level1> list = service.GetAll(); foreach (CDD_Level1 entity in list) { CascadingDropDownNameValue val = new CascadingDropDownNameValue(entity.Level1Name, entity.Level1Id.ToString()); values.Add(val); } return values.ToArray(); } [WebMethod] public static AjaxControlToolkit.CascadingDropDownNameValue[] GetLevel2Data(string knownCategoryValues, string category) { StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); Guid level1Id; if (!kv.ContainsKey("Level1")) return null; level1Id = new Guid(kv["Level1"].ToString()); CDD_Level2Service service = new CDD_Level2Service(); TList<CDD_Level2> list = service.GetByLevel1Id(level1Id); List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>(); foreach (CDD_Level2 entity in list) { CascadingDropDownNameValue val = new CascadingDropDownNameValue(entity.Level2Name, entity.Level2Id.ToString()); values.Add(val); } return values.ToArray(); } } </code>
ScrewTurn Wiki
version 2.0.31.