[Net] [Ajax] Ajax programming Memo -- ComboBox refreshing

Source: Internet
Author: User
Ajax programming memo-ComboBox refreshing

The programming logic is as follows:

1: The background obtains the corresponding lower-level department based on the ID of the higher-level department sent from the front-end, and the composition format is

Department code 1-department name 1 | Department Code 2-department name 2 | department code 3-department name 3 .....

The front-end client splits the string and re-organizes the ComboBox of the lower-level department with JavaScript.

2: Use the request ['comboboxid'] method to retrieve the ComboBox value in the background, without the need for ComboBox. Value

[Article 2nd applies to Asp.net]

JavaScript code:

// After the higher-level department is modified, the lower-level department must follow the change
Function departmentchange ()
{
VaR objdept = Document. All ['cmbdemotid'];
VaR objsubdept = Document. All ['cmbsubdemotid'];

If (objdept & objsubdept)
{
// Ajax call
VaR response = register. refilldept (objdept. value ,'-');

If (response. value! = "")
{
VaR length = 1;

While (length! = 0)
{
VaR length = objsubdept. Options. length;
For (VAR I = 0; I <length; I ++)
Objsubdept. Options. Remove (I );
Length = length/2;
}

VaR stritem = response. value. Split ('| ');

If (stritem. length> 0)
{
For (VAR n = 0; n <stritem. length; n ++)
{
VaR option = Document. createelement ("option ");
Option. value = stritem [N];
Option. Text = stritem [N];
// Alert (option. value );
Objsubdept. Options. Add (option );
}
}
}
}

}

 

Asp.net background server code:

/// <Summary>
/// Obtain the information of the subordinate department after the Department changes
/// </Summary>
/// <Param name = "strdept"> department code-department name </param>
/// <Param name = "strseparetor"> shard symbol </param>
/// <Returns> subordinate department. Format: department 1 | Department 2 | department 3 </returns>
[Ajax. ajaxmethod ()]
Public String refilldept (string strdept, string strseparetor)
{
String strdeptstring = "";

Try
{
String [] stritem = strdept. Split (strseparetor. tochararray ());

If (stritem. length> 1)
{
Olexamdepartment objolexamdepartment = new olexamdepartment ();

Dataset dstdept = objolexamdepartment. getdepartinfo (stritem [0]);

If (dstdept! = NULL)
{
If (dstdept. Tables [0]. Rows. Count> 0)
{
// Returns a string.
For (INT I = 0; I <dstdept. Tables [0]. Rows. Count; I ++)
{
Strdeptstring = strdeptstring + dstdept. tables [0]. rows [I] ["deptcode"]. tostring () + "-" + dstdept. tables [0]. rows [I] ["deptname"]. tostring () + "| ";
}
}
}

If (strdeptstring. length> 0)
{
Strdeptstring = stritem [0] + "-Headquarters |" + strdeptstring. substring (0, strdeptstring. Length-1 );
}
Else
{
Strdeptstring = stritem [0] + "-Headquarters ";
}
}

Return strdeptstring;
}
Catch (exception ex)
{
Return "";
}
}

Related Article

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.