Ajax Programming Memo--combobox No refresh fill

Source: Internet
Author: User
Tags format count net return string split tostring
Ajax| Programming | refresh | no refresh

Programming ideas are as follows:

1: Backstage According to the front of the superior department ID, get the corresponding subordinate departments, and then constitute a format for

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

The client side of the foreground splits from the string, and then combobox the subordinate department with JavaScript

2: In the background to take ComboBox value of the time with request[' Comboboxid '] way to obtain, without combobox.value

[Article 2nd applies to asp.net]

Code for the JavaScript section:

After the parent department has changed, the subordinate department will change
function Departmentchange ()
{
var objdept=document.all[' Cmbdeptid '];
var objsubdept=document.all[' Cmbsubdeptid '];

if (objdept && objsubdept)
{
Ajax calls
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 backend server-side code:

<summary>
Get information about departmental changes that correspond to subordinate departments
</summary>
<param name= "strdept" > Department Code-Department name </param>
<param name= "Strseparetor" > Split symbol </param>
<returns> corresponding 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)
      {
      //Composition return 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]+ "-part |" +strdeptstring.substring (0,strdeptstring.length-1);
}
Else
{
strdeptstring=stritem[0]+ "-part";
}
}

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.