这个是一个webservice方法,返回一个DATASET
[WebMethod(Description="得到市")]
public DataSet GetChengShi(string strType)
{
string strcon="server=(local);database=lsa_anqiu;uid=sa;pwd=sundun";
SqlConnection conn=new SqlConnection(strcon);
string strSelect=string.Format("select chengshi from chengshi where shengfen='{0}' ",strType);
SqlDataAdapter da=new SqlDataAdapter(strSelect,conn);
DataSet ds=new DataSet();
da.Fill(ds);
return ds;
}
public DataSet GetChengShi(string strType)
{
string strcon="server=(local);database=lsa_anqiu;uid=sa;pwd=sundun";
SqlConnection conn=new SqlConnection(strcon);
string strSelect=string.Format("select chengshi from chengshi where shengfen='{0}' ",strType);
SqlDataAdapter da=new SqlDataAdapter(strSelect,conn);
DataSet ds=new DataSet();
da.Fill(ds);
return ds;
}
//得到城市,webservice
function GetChengShiJ(drp)
{
//选中的值(省)
var strS=window.Form1.drpS.value;
//如果市有值则清空
var objList = document.getElementById("drpC");
if (objList.options.length !=0)
{
for (var iDel=0;iDel<objList.options.length;iDel++)
{
objList.options[iDel]=null ;
objList.options.remove(iDel);
iDel--;
}
}
//增加一空列
objList.add(document.createElement("OPTION"));
objList.options[0].text = "";
objList.options[0].value = "";
var xmlData = new ActiveXObject("Msxml.DOMDocument");
xmlData.async = false
//调用webservice,返回一个dataset
var vstr="Service1.asmx/GetChengShi?strType="+strS
xmlData.load( vstr);
xmlValue = xmlData.getElementsByTagName("chengshi");
xmlText = xmlData.getElementsByTagName("chengshi");
for (var i=0; i<xmlValue.length; i++)
{
objList.add(document.createElement("OPTION"));
objList.options[i+1].text = xmlText.item(i).text;
objList.options[i+1].value = xmlValue.item(i).text;
}
}
function GetChengShiJ(drp)
{
//选中的值(省)
var strS=window.Form1.drpS.value;
//如果市有值则清空
var objList = document.getElementById("drpC");
if (objList.options.length !=0)
{
for (var iDel=0;iDel<objList.options.length;iDel++)
{
objList.options[iDel]=null ;
objList.options.remove(iDel);
iDel--;
}
}
//增加一空列
objList.add(document.createElement("OPTION"));
objList.options[0].text = "";
objList.options[0].value = "";
var xmlData = new ActiveXObject("Msxml.DOMDocument");
xmlData.async = false
//调用webservice,返回一个dataset
var vstr="Service1.asmx/GetChengShi?strType="+strS
xmlData.load( vstr);
xmlValue = xmlData.getElementsByTagName("chengshi");
xmlText = xmlData.getElementsByTagName("chengshi");
for (var i=0; i<xmlValue.length; i++)
{
objList.add(document.createElement("OPTION"));
objList.options[i+1].text = xmlText.item(i).text;
objList.options[i+1].value = xmlValue.item(i).text;
}
}
<SELECT id="drpS" runat="server" onchange="GetChengShiJ(this);">
<OPTION selected value="广东">广东</OPTION>
<OPTION value="湖北">湖北</OPTION>
<OPTION value="湖南">湖南</OPTION>
<OPTION value=""></OPTION>
</SELECT><SELECT id="drpC" runat="server">
<OPTION selected></OPTION>
</SELECT>
<OPTION selected value="广东">广东</OPTION>
<OPTION value="湖北">湖北</OPTION>
<OPTION value="湖南">湖南</OPTION>
<OPTION value=""></OPTION>
</SELECT><SELECT id="drpC" runat="server">
<OPTION selected></OPTION>
</SELECT>
注意,JAVASCRIPT调用WEBSERVICE需要在WEB。CONFIG里设置
<webServices>
<protocols>
<add name="HttpSoap" />
<add name="HttpPost" />
<add name="HttpGet" />
<add name="Documentation" />
</protocols>
</webServices>
<protocols>
<add name="HttpSoap" />
<add name="HttpPost" />
<add name="HttpGet" />
<add name="Documentation" />
</protocols>
</webServices>