The usage of CascadingDropDown in AjaxControlToolkit _ Practical skills

Source: Internet
Author: User

Use Table control position to realize just recently in the Learning AjaxControlToolkit control, think of the CascadingDropDown Cascade dropdown is a cascade linkage of the down extension is very useful
Let's introduce some of the properties of the next CascadingDropDown:
TargetControlID the target control ID is the ID of the control DropDownList
Category category (Next CascadingDropDown takes the name of a class that comes with the last pass value, which is described in detail in the following code)
PromptText message no longer clicks the information displayed before the control DropDownList control
Loadingtext Load Data Information if the data is more, give the user a hint
ServicePath the path to the webservice that provides the data method
Servicemethod methods of providing data in Web services
Parentcontrolid the ID of the ancestor DropDownList that controls whether this CascadingDropDown control is available DropDownList
SelectedValue the default selected data
Process:
Add ScriptManager Control
Add three DropDownList controls
Add three CascadingDropDown controls
Add a WebService page to the test example
First of all, write the data method in WebService, the general practice is that the page has several CascadingDropDown controls, add a [WebMethod] method
Of course, you can use some skills to integrate these methods together (these skills require the accumulation of code, the niche is not yet accumulated, but also hope that the masters of many exhibitions)
Here is a data method annotation in a page of a Web service in an example (please advise the prawns in the wrong place):
Where it is necessary to add [System.Web.Script.Services.ScriptService] above the class
[WebMethod]

Copy Code code as follows:

Public ajaxcontroltoolkit.cascadingdropdownnamevalue[] Getordersbyemployeeid (string knowncategoryvalues, String Category
{

String dictionary This class has been used to see how people write.
can also be used: string [] strvalues=knowncategoryvalues.split (': ', '; ');
Then take the value: Strvalues[0] is the name strvalues[1] is value?

System.Collections.Specialized.StringDictionary kv = cascadingdropdown.parseknowncategoryvaluesstring ( Knowncategoryvalues);
int iemployee;

Where employee is a category passed in the Knowncategoryvalues parameter passed by the parent control, and the category value of the parent control is "Employee"
The value of the knowncategoryvalues is: "Employeename:value" type
If the following value is added to the [WebMethod] method in the parent control
List. ADD (New Ajaxcontroltoolkit.cascadingdropdownnamevalue ("John", "123"));
Then Knowncategoryvalues is "employee John: 123;" (If there is a mistake here, please let the prawns guide)
The category in the method is the value of the category, where the shrimp I am puzzled, is this value the category value of this control or the value of the parent control?
I think it's the category property of the category CascadingDropDown that calls this method, because this property of the parent control is judged in the knowncategoryvalues value.

if (!kv. ContainsKey ("Employee") | | ! Int32.TryParse (kv["Employee", out IEmployee))
{
return null;
}
The following data method can be changed according to the actual situation in the project, here I use a prawn blog on a method to do the example, because I write the need to add some judgment in the SQL statement, and the data table is unfamiliar,
String stringconnection = "server=.;D ATABASE=NORTHWIND;UID=SA;PWD=SL ";
System.Data.SqlClient.SqlConnection conn= New System.Data.SqlClient.SqlConnection (stringconnection);
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand ("Select OrderID from Orders WHERE" EmployeeID = "+ IEmployee);
Cmd. Connection = conn;
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter (cmd);
System.Data.DataSet ds = new System.Data.DataSet ();
Da. Fill (DS);
Cmd. Connection.close ();
//
system.collections.generic.list<ajaxcontroltoolkit.cascadingdropdownnamevalue> List = new System.collections.generic.list<cascadingdropdownnamevalue> ();

Values in the Drop-down list
foreach (System.Data.DataRow Dr in DS. Tables[0]. Rows)
{
String sorder=dr["OrderID"]. ToString ();
int iorder= (int) dr["OrderID"];
Cascadingdropdownnamevalue ("name", "value") Name is the value of the DropDownList that is displayed in DropDownList text value
The SelectedValue in DropDownList is passed to the WebService value in the Knowncategoryvalues method of the next control DropDownList CascadingDropDown call

List. ADD (New Ajaxcontroltoolkit.cascadingdropdownnamevalue (Sorder,iorder.tostring ()));
}
Return list. ToArray ();
}

The following is the Setup code in the page:
The required Scriptmanger control on the page.
Copy Code code as follows:

<asp:dropdownlist id= "DropDownList1" runat= "Server" >
</asp:DropDownList>
<asp:dropdownlist id= "DropDownList2" runat= "Server" >
</asp:DropDownList>
<asp:dropdownlist id= "DropDownList3" runat= "Server" >
</asp:dropdownlist><br/>
<cc1:cascadingdropdown id= "CascadingDropDown1" runat= "Server" category= "Employee" enabled= "True" prompttext= " Select Employee "servicemethod=" GetEmployees "targetcontrolid=" DropDownList1 "servicepath=" Autocomplete.asmx ">
</cc1:CascadingDropDown>
<cc1:cascadingdropdown id= "CASCADINGDROPDOWN2" runat= "Server" parentcontrolid= "DropDownList1" category= "order" Enabled= "True" prompttext= "Select Order" servicemethod= "Getordersbyemployeeid" targetcontrolid= "DropDownList2" Servicepath= "Autocomplete.asmx" >
</cc1:CascadingDropDown>
<cc1:cascadingdropdown id= "CascadingDropDown3" runat= "Server" parentcontrolid= "DropDownList2" enabled= "True" prompttext= "Select pice" servicemethod= "Getdetailsbyorder" targetcontrolid= "DropDownList3" servicepath= " Autocomplete.asmx "category=" Pice ">
</cc1:CascadingDropDown>

All examples here will not add, the Internet a lot of prawns have written!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.