Three-Level linkage drop-down menu

Source: Internet
Author: User

Write CS,
AJAX can also be using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. Data. sqlclient;
/// <Summary>
/// Summary of provcityservstat
/// This class is mainly used when the province/city/service station are all pulled into the judgment, the province and city teachers are both autopostback
/// </Summary>
Public class provcityservstat
{
Public dropdownlist prov;
Public dropdownlist city;
Public dropdownlist servstat;
Public String servstat_id;
Public provcityservstat ()
{
//
// Todo: add the constructor logic here
//
}
// Drop-down list of province bound
Public void databindtoprov ()
{
Sqlconnection con = dB. createsqlconneciton ();
Con. open ();
Sqlcommand cmd = new sqlcommand ("select * From t_prov", con );
Sqldatareader SDR = cmd. executereader ();
This. Prov. datasource = SDR;
This. Prov. datatextfield = "prov_name ";
This. Prov. datavaluefield = "prov_id ";
This. Prov. databind ();
SDR. Close ();
Con. Close ();
}

// Bind the city drop-down list
Public void databindtocity ()
{
Sqlconnection con = dB. createsqlconneciton ();
Con. open ();
Sqlcommand cmd = new sqlcommand ("select * From t_city where city_provid =" + this. Prov. selectedvalue, con );
Sqldatareader SDR = cmd. executereader ();
This. City. datasource = SDR;
This. City. datatextfield = "city_name ";
This. City. datavaluefield = "city_id ";
This. City. databind ();
SDR. Close ();
Con. Close ();
}

// Bind the service station
Public void databindtoservstat ()
{
If (this. City. selectedvalue! = "")
{
Sqlconnection con = dB. createsqlconneciton ();
Con. open ();
Sqlcommand cmd = new sqlcommand ("select * From t_servstat where servstat_cityid =" + this. City. selectedvalue, con );
Sqldatareader SDR = cmd. executereader ();
This. servstat. datasource = SDR;
This. servstat. datatextfield = "servstat_name ";
This. servstat. datavaluefield = "servstat_id ";
This. servstat. databind ();
SDR. Close ();
Con. Close ();
}
Else
{
This. servstat. Items. Clear ();
}
}

// It is generally used for the drop-down of provinces, cities, and service stations when new users are added.
Public void databindadd ()
{
Databindtoprov ();
Databindtocity ();
Databindtoservstat ();
}

// When the province drop-down changes
Public void databinddropdownprov ()
{
Databindtocity ();
Databindtoservstat ();
}

// The following is used for modification. Based on the known servstat_id, determine the service station, city, and province.
Public void databindmod ()
{
Sqlconnection con = dB. createsqlconneciton ();
Con. open ();
Sqlcommand cmd = new sqlcommand ("select * From t_servstat, t_city, t_prov where prov_id = city_provid and city_id = servstat_cityid and servstat_id =" + servstat_id, con );
Sqldatareader SDR = cmd. executereader ();
If (SDR. Read ())
{
Databindmodprov (SDR ["prov_id"]. tostring ());
Databindmodcity (SDR ["prov_id"]. tostring (), SDR ["city_id"]. tostring ());
Databindmodservstat (SDR ["city_id"]. tostring (), SDR ["servstat_id"]. tostring ());
}
SDR. Close ();
Con. Close ();
}

// Bind to the province at the time of Modification
Public void databindmodprov (string prov_id)
{
Sqlconnection con = dB. createsqlconneciton ();
Con. open ();
Sqlcommand cmd = new sqlcommand ("select * From t_prov", con );
Sqldatareader SDR = cmd. executereader ();
This. Prov. Items. Clear ();
Int I = 0;
While (SDR. Read ())
{
This. Prov. Items. insert (I, new listitem (SDR ["prov_name"]. tostring (), SDR ["prov_id"]. tostring ()));
If (prov_id = SDR ["prov_id"]. tostring ())
{
This. Prov. items [I]. Selected = true;
}
I ++;
}
SDR. Close ();
Con. Close ();
}

// Bind to the modified City
Public void databindmodcity (string prov_id, string city_id)
{
Sqlconnection con = dB. createsqlconneciton ();
Con. open ();
Sqlcommand cmd = new sqlcommand ("select * From t_city where city_provid =" + prov_id, con );
Sqldatareader SDR = cmd. executereader ();
This. City. Items. Clear ();
Int I = 0;
While (SDR. Read ())
{
This. City. Items. insert (I, new listitem (SDR ["city_name"]. tostring (), SDR ["city_id"]. tostring ()));
If (city_id = SDR ["city_id"]. tostring ())
{
This. City. items [I]. Selected = true;
}
I ++;
}
SDR. Close ();
Con. Close ();
}

// Bind to the service station at the time of Modification
Public void databindmodservstat (string city_id, string servstat_id)
{
Sqlconnection con = dB. createsqlconneciton ();
Con. open ();
Sqlcommand cmd = new sqlcommand ("select * From t_servstat where servstat_cityid =" + city_id, con );
Sqldatareader SDR = cmd. executereader ();
This. servstat. Items. Clear ();
Int I = 0;
While (SDR. Read ())
{
This. servstat. Items. insert (I, new listitem (SDR ["servstat_name"]. tostring (), SDR ["servstat_id"]. tostring ()));
If (servstat_id = SDR ["servstat_id"]. tostring ())
{
This. servstat. items [I]. Selected = true;
}
I ++;
}
SDR. Close ();
Con. Close ();
}
}

For more information, see mine.
Note: The drop-down autopostback must be prefixed

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.