一个用webservice behavior实现的三级联动下拉列表框
2006-11-01 14:43
821 查看
一个用webservice behavior实现的三级联动下拉列表框
我做了一个三级联动的下拉列表框,后台用webservice,前台用webservice behavior与后台通讯。请高手们多提改进意见。
server端:(service1.asmx.cs)
using System;
using System.Text;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace WebService1
...{
/**//// <summary>
/// Summary description for Service1.
/// </summary>
public class Service1 : System.Web.Services.WebService
...{
SqlConnection con;
public Service1()
...{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}
Component Designer generated code#region Component Designer generated code
/**//// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
...{
string dsn = ConfigurationSettings.AppSettings["yitong"];
con=new SqlConnection(dsn);
}
#endregion
/**//// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
...{
}
[WebMethod]
public string fenlei()
...{
string str="select distinct substring(code,1,3) as fenlei from jinan ";
SqlCommand cmd=new SqlCommand(str,con);
cmd.Connection.Open();
SqlDataReader dr=cmd.ExecuteReader();
string s="请选择:";
while(dr.Read())
...{
s += ","+dr["fenlei"].ToString();
}
return s;
}
[WebMethod]
public string leixing(string q)
...{
string str="select distinct type from jinan where code like '"+q+"%'";
SqlCommand cmd=new SqlCommand(str,con);
cmd.Connection.Open();
SqlDataReader dr=cmd.ExecuteReader();
string s="请选择:";
while(dr.Read())
...{
s += ","+dr["type"].ToString();
}
return s;
}
[WebMethod]
public string haoduan(string q)
...{
string str="select distinct substring(code,4,4) as haoduan from jinan where type='"+q+"'";
SqlCommand cmd=new SqlCommand(str,con);
cmd.Connection.Open();
SqlDataReader dr=cmd.ExecuteReader();
string s="请选择:";
while(dr.Read())
...{
s += ","+dr["type"].ToString();
}
return s;
}
client端(htmlpage1.htm)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 7.0">
<TITLE></TITLE>
<script id="clientEventHandlersJS" language="javascript">...
<!--
var icallid;
var icallid1;
var icallid2;
function window_onload() ...{
service.useService("/service1.asmx?WSDL","myselect");
icallid=service.myselect.callService(fenlei,"fenlei");
}
function fenlei(result)
...{
var m=result.value;
var a=m.split(",")
for(var i=0;i<a.length;i++)
...{
window.s1.options[i]=new Option(a[i],a[i]);
}
}
function s1_onchange() ...{
var x=s1.value;
icallid1=service.myselect.callService(leixing,"leixing",x);
}
function s2_onchange() ...{
var x=s2.value;
icallid2=service.myselect.callService(haoduan,"haoduan",x);
}
function leixing(result)...{
var m=result.value;
var a=m.split(",")
window.s2.length=0;
for(var i=0;i<a.length;i++)
...{
window.s2.options[i]=new Option(a[i],a[i]);
}
}
function haoduan(result)...{
var m=result.value;
var a=m.split(",")
window.s3.length=0;
for(var i=0;i<a.length;i++)
...{
window.s3.options[i]=new Option(a[i],a[i]);
}
}
//-->
</script>
</HEAD>
<BODY onload="return window_onload()">
<div id="service" style="behavior:url(webservice.htc)">
</div>
<select id="s1" onchange="return s1_onchange()"> </select><select id="s2" onchange="return s2_onchange()"></select>
<select id="s3"></select>
</HTML>
我做了一个三级联动的下拉列表框,后台用webservice,前台用webservice behavior与后台通讯。请高手们多提改进意见。
server端:(service1.asmx.cs)
using System;
using System.Text;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace WebService1
...{
/**//// <summary>
/// Summary description for Service1.
/// </summary>
public class Service1 : System.Web.Services.WebService
...{
SqlConnection con;
public Service1()
...{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}
Component Designer generated code#region Component Designer generated code
/**//// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
...{
string dsn = ConfigurationSettings.AppSettings["yitong"];
con=new SqlConnection(dsn);
}
#endregion
/**//// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
...{
}
[WebMethod]
public string fenlei()
...{
string str="select distinct substring(code,1,3) as fenlei from jinan ";
SqlCommand cmd=new SqlCommand(str,con);
cmd.Connection.Open();
SqlDataReader dr=cmd.ExecuteReader();
string s="请选择:";
while(dr.Read())
...{
s += ","+dr["fenlei"].ToString();
}
return s;
}
[WebMethod]
public string leixing(string q)
...{
string str="select distinct type from jinan where code like '"+q+"%'";
SqlCommand cmd=new SqlCommand(str,con);
cmd.Connection.Open();
SqlDataReader dr=cmd.ExecuteReader();
string s="请选择:";
while(dr.Read())
...{
s += ","+dr["type"].ToString();
}
return s;
}
[WebMethod]
public string haoduan(string q)
...{
string str="select distinct substring(code,4,4) as haoduan from jinan where type='"+q+"'";
SqlCommand cmd=new SqlCommand(str,con);
cmd.Connection.Open();
SqlDataReader dr=cmd.ExecuteReader();
string s="请选择:";
while(dr.Read())
...{
s += ","+dr["type"].ToString();
}
return s;
}
client端(htmlpage1.htm)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 7.0">
<TITLE></TITLE>
<script id="clientEventHandlersJS" language="javascript">...
<!--
var icallid;
var icallid1;
var icallid2;
function window_onload() ...{
service.useService("/service1.asmx?WSDL","myselect");
icallid=service.myselect.callService(fenlei,"fenlei");
}
function fenlei(result)
...{
var m=result.value;
var a=m.split(",")
for(var i=0;i<a.length;i++)
...{
window.s1.options[i]=new Option(a[i],a[i]);
}
}
function s1_onchange() ...{
var x=s1.value;
icallid1=service.myselect.callService(leixing,"leixing",x);
}
function s2_onchange() ...{
var x=s2.value;
icallid2=service.myselect.callService(haoduan,"haoduan",x);
}
function leixing(result)...{
var m=result.value;
var a=m.split(",")
window.s2.length=0;
for(var i=0;i<a.length;i++)
...{
window.s2.options[i]=new Option(a[i],a[i]);
}
}
function haoduan(result)...{
var m=result.value;
var a=m.split(",")
window.s3.length=0;
for(var i=0;i<a.length;i++)
...{
window.s3.options[i]=new Option(a[i],a[i]);
}
}
//-->
</script>
</HEAD>
<BODY onload="return window_onload()">
<div id="service" style="behavior:url(webservice.htc)">
</div>
<select id="s1" onchange="return s1_onchange()"> </select><select id="s2" onchange="return s2_onchange()"></select>
<select id="s3"></select>
</HTML>
相关文章推荐
- 用php和ajax写一个省市区的三级联动,实现地区的下拉选择
- 省市区三级联动菜单实现及三级联动下拉列表框默认值的设置
- javascript:Date篇之实现年、月、日下拉列表框的三级联动
- 用Ajax.net实现的一个无刷新的多级联动下拉列表框
- 省市区三级联动菜单实现及三级联动下拉列表框默认值的设置
- 用Ajax.net实现的一个无刷新的多级联动下拉列表框
- 用XML实现三级联动下拉列表框
- JQuery+WebService实现DropDownlist无刷新三级联动
- 使用js实现一个地址的三级联动
- 实现三级联动下拉框&nbsp;下拉列表…
- 构造函数实现一个省市县三级联动
- JavaScript实现二级、多级(N级)联动下拉列表框更新版,支持IE6,FireFox,函数和类两种调用方式,支持到N级,非常通用。
- php jquery ajax json 全国省市区三级联动下拉列表 简单实现
- 在InfoPath Forms Services中实现联动下拉列表框(二)
- JavaScript实现二级、多级(N级)联动下拉列表框更新版(续)- 四级联动的演示
- JavaScript实现二级、多级(N级)联动下拉列表框更新版,支持IE6,FireFox,函数和类两种调用方式,支持到N级,非常通用。
- JavaScript实现二级、多级(N级)联动下拉列表框更新版(续)- 四级联动的演示
- ASP.NET MVC + Jquery 实现Ajax下拉框数据三级联动
- 润乾报表三级下拉数据集联动实现
- Android实现三级联动下拉框 下拉列表spinner