1、引用js文件:
<script type="text/javascript" src="/JavaScript/jquery-1.2.6.pack.js"></script>
2、编写js:
//业务种类改变
function sel_YWZL_Change(num)
{
var val = document.getElementById('GV_CommonData_ctl' + num + "_sel_YWZL").value;
var cx = document.getElementById('GV_CommonData_ctl' + num + "_sel_FYMC");
$.ajax({ type: "get", dataType: "html", url: "GetSFLC.aspx?YWZL="+encodeURI(val)+"×tamp=" + new Date().getTime(), data: "", success: function(data)
{
func_getCX(data,cx);
}});
}
//返回结果调用js
function func_getCX(fyxm, obj)
{
var arrsel = fyxm.split(',');
var alen = arrsel.length;
obj.options.length = 0;
var count = 0;
for(var i = 0; i < alen; i++)
{
obj.options.add(new Option(arrsel[i].toString(),arrsel[i].toString()));
if(obj.options[i].value != "运费")
count = count+1;
}
if(count == alen)
{
obj.options.add(new Option("运费","运费"));
}
obj.value = "运费";
}
3、新建异步调用页面:GetSFLC.aspx
if (Request["YWZL"] != null && Request["YWZL"].ToString() != string.Empty)
{
string ywzl = Request["YWZL"].ToString();
DataSet ds_fymc = new DataSet();
if (ywzl == "不限")
{
ds_fymc = _BasicDAL.GetProc("select FYXM from YWLXFYXMSZ where YWLX='运输'");
}
else
{
ds_fymc = _BasicDAL.GetProc("select FYXM from YWLXFYXMSZ where YWZL='" + ywzl + "' and YWLX='运输'");
}
if (ds_fymc != null && ds_fymc.Tables.Count > 0)
{
string[] DDParm = new string[] { "FYXM" };
DataTable dt = _gl.DefinitionTable(DDParm);
string fy = "";
for (int s = 0; s < ds_fymc.Tables[0].Rows.Count; s++)
{
fy += ds_fymc.Tables[0].Rows[s][0].ToString().TrimEnd(',') + ',';
}
string[] fyxms = fy.TrimEnd(',').Split(',');
for (int g = 0; g < fyxms.Length; g++)
{
DataRow dr = dt.NewRow();
dr["FYXM"] = fyxms[g].ToString();
dt.Rows.Add(dr);
}
DataTable dft = dt.DefaultView.ToTable(true, "FYXM");
string fym = "";
for (int x = 0; x < dft.Rows.Count; x++)
{
fym += dft.Rows[x][0].ToString() + ',';
}
Response.Write(fym.TrimEnd(','));
}
else
{
Response.Write("");
}
}
Response.End();