1.html代码:
<SCRIPT language="javascript">
//部别------------------------------
function excclassResult()
{
var excclass=document.getElementById("exc_dept");
AjaxMethod.GetexcclassList(excclass.value,get_excclass_Result_CallBack);
}
function get_excclass_Result_CallBack(response)
{
if (response.value != null)
{
//debugger;
document.all("exc_class").length=0;
var ds = response.value;
//alert (ds.Tables[0].Rows[0].escclass);
if(ds != null && typeof(ds) == "object" && ds.Tables != null)
{
for(var i=0; i<ds.Tables[0].Rows.length; i++)
{
var name=ds.Tables[0].Rows[i].escclass;
var id=ds.Tables[0].Rows[i].escclassid;
document.all("exc_class").options.add(new Option(name,id));
}
}
}
return
}
//站别----------------------------------------
function exczbResult()
{
//var a=document.all("exc_class").options[document.all("exc_class").SelectedIndex].Value;
//alert (a);
var exczb=document.getElementById("exc_class");
//alert(exczb.value);
//var exczb=document.all("exc_dept");
//alert (exczb.value);
AjaxMethod.GetexczbList(exczb.value,get_exczb_Result_CallBack);
}
function get_exczb_Result_CallBack(response)
{
//alert (response.value)
if (response.value != null)
{
document.all("exc_zb").length=0;
var ds = response.value;
if(ds != null && typeof(ds) == "object" && ds.Tables != null)
{
for(var i=0; i<ds.Tables[0].Rows.length; i++)
{
var name=ds.Tables[0].Rows[i].exczb;
var id=ds.Tables[0].Rows[i].exczbID;
document.all("exc_zb").options.add(new Option(name,id));
}
}
}
return
}
function getData()
{
var excdept=document.getElementById("exc_dept");
var pindex = excdept.selectedIndex;
var pValue = excdept.options[pindex].value;
var pText = excdept.options[pindex].text;
var excclass=document.getElementById("exc_class");
var cindex = excclass.selectedIndex;
var cValue = excclass.options[cindex].value;
var cText = excclass.options[cindex].text;
var exczb=document.getElementById("exc_zb");
var aindex = exczb.selectedIndex;
var aValue = exczb.options[aindex].value;
var aText = exczb.options[aindex].text;
}
</SCRIPT>
<tr>
<td>发现厂别</td>
<td>
<asp:dropdownlist id="Dropdownlist1" runat="server"></asp:dropdownlist>
</td>
<td>事业部别</td>
<td>
<asp:dropdownlist id="Dropdownlist2" runat="server"></asp:dropdownlist>
</td>
</tr>
<tr>
<td>站别名称</td>
<td colSpan="3" >
<tr>
<td width="137" rowSpan="3">
<asp:listbox id="Listbox1" runat="server" Selectinotallow="Multiple"></asp:listbox>
</td>
2.cs代码
Ajax.Utility.RegisterTypeForAjax(typeof(AjaxMethod));
if(!Page.IsPostBack)
{
this.exc_dept.DataSource=AjaxMethod.GetexcdeptList();
this.exc_dept.DataTextField="excdept";
this.exc_dept.DataValueField="excdeptid";
this.exc_dept.DataBind();
this.exc_dept.Attributes.Add("onclick","excclassResult();");
this.exc_class.Attributes.Add("onclick","exczbResult();");
} 3.Ajax代码
public class AjaxMethod
{
// private Connection conFlowER;
public AjaxMethod()
{
//
// TODO: 在此处添加构造函数逻辑
// conFlowER = new Connection(DatabaseType.Kernal);
// // string sql="select item_name,item_value from fm_code_list where form_kind='BQS.FORM.T601' and field_name='F01'";
}
#region GetexcdeptList
public static DataSet GetexcdeptList()
{
string sql="select * from excdept";
return GetDataSet(sql);
}
#endregion
#region GetexcclassList
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
public DataSet GetexcclassList(int excdeptid)
{
string sql="select * from excclass where father="+excdeptid;
// string sql="select item_name,item_value from fm_code_list where form_kind='BQS.FORM.T601' and field_name='F02'";
return GetDataSet(sql);
}
#endregion
#region GetexczbList
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
public DataSet GetexczbList(int excclassid)
{
string sql="select * from exczb where father="+excclassid;
// string sql="select item_name,item_value from fm_code_list where form_kind='BQS.FORM.T601' and field_name='F03'";
return GetDataSet(sql);
}
#endregion
#region GetDataSet
public static DataSet GetDataSet(string sql)
{
string Cnotallow=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlDataAdapter sda =new SqlDataAdapter(sql,ConnectionString);
DataSet ds=new DataSet();
sda.Fill(ds);
return ds;
}
#endregion
}
4.web.config
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
</httpHandlers>5.ajax.dll下载/Files/singlepine/Ajax.rar