62,046
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript" src="ajax_func.js"></script>
<script>
function changsheng(va)
{
if(va!='0')
{
var city = document.getElementById("city");
city.disabled=false;
var qu = document.getElementById("qu");
qu.disabled=true;
var f=document.getElementById("qu");
f.options.length=1;
var url="Handler.ashx?type=sheng&id="+va;
send_request("GET",url,null,"text",populateClass3);
}
}
function populateClass3(){
var f=document.getElementById("city");
if(http_request.readyState==4){
if(http_request.status==200){
var list=http_request.responseText;
var classList=list.split("|");
f.options.length=1;
for(var i=0;i<classList.length;i++){
var tmp=classList[i].split(",");
f.add(new Option(tmp[1],tmp[0]));
}
}else{
alert("您所请求的页面有异常。");
}
}
}
</script>
<td ><select id="sheng" runat="server" onchange="changsheng(this.value)" style="width: 121px">
<option selected="selected" value="0">--选择产品类型--</option></select></td>
<td ><select id="city" runat="server" onchange="changshi(this.value)">
<option>--请选产品型号--</option></select></td>
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
string type = context.Request.QueryString["type"];
if (type.Equals("sheng"))
{
string id = context.Request.QueryString["id"];
context.Response.ContentType = "text/plain";
context.Response.Write(getSheng(id));//这个是从数据库中根据传来省的id 查询出来的。市的名字和主键,主键以便去查区的名字
}
}
public string getSheng(string sheng)
{
string mystring = "select * from tb_barcodeType";
DataSet ds = dataOperate.getDataset(mystring, "tb_barcodeType");
string str = "";
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (i == ds.Tables[0].Rows.Count - 1)
{
str += ds.Tables[0].Rows[i]["code"].ToString() + "," + ds.Tables[0].Rows[i]["name"].ToString();
}
else
{
str += ds.Tables[0].Rows[i]["code"].ToString() + "," + ds.Tables[0].Rows[i]["name"].ToString() + "|";
}
}
return str.Trim();
}
public bool IsReusable {
get {
return false;
}
}
}
function changsheng(va)
{
if(va!='0')
{
var city = document.getElementById("city");
city.disabled=false;
var qu = document.getElementById("qu");
qu.disabled=true;
var f=document.getElementById("qu");
f.options.length=1;
var url="Handler.ashx?type=sheng&id="+va;
send_request("GET",url,null,"text",populateClass3);
}
}
function populateClass3(){
var f=document.getElementById("city");
if(http_request.readyState==4){
if(http_request.status==200){
var list=http_request.responseText;
var classList=list.split("|");
f.options.length=1;
for(var i=0;i<classList.length;i++){
var tmp=classList[i].split(",");
f.add(new Option(tmp[1],tmp[0]));
}
}else{
alert("您所请求的页面有异常。");
}
}
}