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 "";
}
}