A three-level linkage Drop-down list box implemented with WebService behavior

Source: Internet
Author: User
Tags dsn split tostring web services visual studio
web| Dropdown | dropdown list I did a three-level linkage drop-down list box, the background with WebService, the foreground with WebService behavior and background communication. Please make more suggestions to improve the experts.

Server end: (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 are required by the ASP.net Web Services Designer
InitializeComponent ();
}

#region Component Designer generated code
<summary>
Required to Designer support-do not modify
The contents is with the Code Editor.
</summary>
private void InitializeComponent ()
{
String DSN = configurationsettings.appsettings["Yitong"];

Con=new SqlConnection (DSN);
}
#endregion

<summary>
Clean up any 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= "Please select:";
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= "Please select:";
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= "Please select:";
while (Dr. Read ())
{
s = = "," +dr["type"]. ToString ();
}
return s;
}


Client Side (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>




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.