Ajax implementation without any new three linkage drop-down box

Source: Internet
Author: User

<HTML>
<Head>
<Title> Ajax implementation without any new three linkage drop-down box </title>
<Meta content = "Microsoft Visual Studio. NET 7.1" name = "generator">
<Meta content = "C #" name = "code_language">
<Meta content = "JavaScript" name = "vs_defaultclientscript">
<Meta content = "http://schemas.microsoft.com/intellisense/ie5" name = "vs_targetschema">
<Script language = "JavaScript">
// City ------------------------------
Function cityresult ()
{
VaR city = Document. getelementbyid ("dropdownlist1 ");
Ajaxmethod. getcitylist (city. Value, get_city_result_callback );
}

Function get_city_result_callback (response)
{
If (response. value! = NULL)
{
// Debugger;
Document. All ("dropdownlist2"). Length = 0;
VaR DS = response. value;
If (Ds! = NULL & typeof (DS) = "object" & Ds. tables! = NULL)
{
For (VAR I = 0; I <Ds. Tables [0]. Rows. length; I ++)
{
VaR name = Ds. Tables [0]. Rows [I]. City;
VaR id = Ds. Tables [0]. Rows [I]. cityid;
Document. All ("dropdownlist2"). Options. Add (New Option (name, ID ));
}
}
}
Return
}
// City ----------------------------------------
Function arearesult ()
{
VaR area = Document. getelementbyid ("dropdownlist2 ");
Ajaxmethod. getarealist (area. Value, get_area_result_callback );
}
Function get_area_result_callback (response)
{
If (response. value! = NULL)
{
Document. All ("dropdownlist3"). Length = 0;
VaR DS = response. value;
If (Ds! = NULL & typeof (DS) = "object" & Ds. tables! = NULL)
{
For (VAR I = 0; I <Ds. Tables [0]. Rows. length; I ++)
{
VaR name = Ds. Tables [0]. Rows [I]. area;
VaR id = Ds. Tables [0]. Rows [I]. areaid;
Document. All ("dropdownlist3"). Options. Add (New Option (name, ID ));
}
}
}
Return
}
Function getdata ()
{
VaR province = Document. getelementbyid ("dropdownlist1 ");
VaR pindex = province. selectedindex;
VaR pvalue = province. Options [pindex]. value;
VaR ptext = province. Options [pindex]. text;

VaR city = Document. getelementbyid ("dropdownlist2 ");
VaR cIndex = city. selectedindex;
VaR cvalue = city. Options [cIndex]. value;
VaR ctext = city. Options [cIndex]. text;

VaR area = Document. getelementbyid ("dropdownlist3 ");
VaR aindex = area. selectedindex;
VaR avalue = area. Options [aindex]. value;
VaR atext = area. Options [aindex]. text;

VaR TXT = Document. getelementbyid ("textbox1 ");

Document. getelementbyid ("<% = textbox1.clientid %> "). innertext = "province:" + pvalue + "|" + ptext + "City:" + cvalue + "|" + ctext + "area: "+ avalue +" | "+ atext;
}
</SCRIPT>
</Head>
<Body ms_positioning = "gridlayout">
<Form ID = "form1" method = "Post" runat = "server">
<Table id = "Table1" style = "Z-INDEX: 101; left: 96px; position: absolute; top: 32px" cellspacing = "1"
Cellpadding = "1" width = "300" border = "1" bgcolor = "# ccff66">
<Tr>
<TD> province and city </TD>
<TD> <asp: dropdownlist id = "dropdownlist1" runat = "server"> </ASP: dropdownlist> </TD>
</Tr>
<Tr>
<TD> city </TD>
<TD> <asp: dropdownlist id = "dropdownlist2" runat = "server"> </ASP: dropdownlist> </TD>
</Tr>
<Tr>
<TD> city </TD>
<TD> <asp: dropdownlist id = "dropdownlist3" runat = "server"> </ASP: dropdownlist> </TD>
</Tr>
</Table>
<Asp: textbox id = "textbox1" style = "Z-INDEX: 102; left: 416px; position: absolute; top: 48px" runat = "server"
Width = "pixel PX"> </ASP: textbox> <input style = "Z-INDEX: 103; left: 456px; width: 56px; position: absolute; top: 96px; height: 24px"
Type = "button" value = "test" onclick = "getdata ();">
</Form>
</Body>
</Html> 2.cs Code
Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Namespace ajaxtest
{
/** // <Summary>
/// Summary description for webform1.
/// </Summary>
Public class webform1: system. Web. UI. Page
{
Protected system. Web. UI. webcontrols. dropdownlist dropdownlist1;
Protected system. Web. UI. webcontrols. dropdownlist dropdownlist2;
Protected system. Web. UI. webcontrols. textbox textbox1;
Protected system. Web. UI. webcontrols. dropdownlist dropdownlist3;

Private void page_load (Object sender, system. eventargs E)
{
Ajax. Utility. registertypeforajax (typeof (ajaxmethod ));
If (! Page. ispostback)
{
This. dropdownlist1.datasource = ajaxmethod. getprovincelist ();
This. dropdownlist1.datatextfield = "Province ";
This. dropdownlist1.datavaluefield = "provinceid ";
This. dropdownlist1.databind ();

This. dropdownlist1.attributes. Add ("onclick", "cityresult ();");
This. dropdownlist2.attributes. Add ("onclick", "arearesult ();");
}
}

Web Form Designer generated code # region web form designer generated code
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}

/** // <Summary>
/// Required method for designer support-do not modify
/// The contents of this method with the code editor.
/// </Summary>
Private void initializecomponent ()
{
This. Load + = new system. eventhandler (this. page_load );

}
# Endregion
}
} 3. ajaxmethod
Using system;
Using system. Data;
Using system. Data. sqlclient;
Namespace ajaxtest
{
/** // <Summary>
/// Summary description for ajaxmethod.
/// </Summary>
Public class ajaxmethod
{
Getprovincelist # region getprovincelist
Public static dataset getprovincelist ()
{
String SQL = "select * From Province ";
Return getdataset (SQL );
}
# Endregion

Getcitylist # region getcitylist
[Ajax. ajaxmethod (Ajax. httpsessionstaterequirement. Read)]
Public dataset getcitylist (INT provinceid)
{
String SQL = "select * from city where Father =" + provinceid;
Return getdataset (SQL );
}
# Endregion

Getarealist # region getarealist
[Ajax. ajaxmethod (Ajax. httpsessionstaterequirement. Read)]
Public dataset getarealist (INT cityid)
{
String SQL = "select * from area where Father =" + cityid;
Return getdataset (SQL );
}
# Endregion

getdataset # region getdataset
Public static dataset getdataset (string SQL)
{< br> string connectionstring = system. configuration. configurationsettings. appsettings ["connectionstring"];
sqldataadapter SDA = new sqldataadapter (SQL, connectionstring);
dataset DS = new dataset ();
SDA. fill (DS);
return Ds;
}< BR ># endregion
}< BR >} 4. web. config


5. ajax. DLL download/files/singw.ine/ajax.rar

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.