Implementation example of Ajax linkage drop-down box

Source: Internet
Author: User
The implementation example of the Ajax linkage drop-down box is Ajax technology, and refreshing is positive, but it is completed at an imperceptible speed. the reason why XMLHTTP sacrifices the page is that we cannot see the refresh because all work is done on the sacrifice page. The "tossing" of "turning the river and the sea" in it is invisible and inefficient!
String 8

Http://ajaxpro.schwarz-interactive.de/download/ajaxpro.zip ajaxpro. dll

String 6

Web. config
<? XML version = "1.0"?>
<Configuration>
<System. Web>
<Httphandlers>
<Add verb = "post, get" Path = "ajax/*. ashx" type = "Ajax. pagehandlerfactory, Ajax"/>
<Add verb = "post, get" Path = "ajaxpro/*. ashx" type = "ajaxpro. ajaxhandlerfactory, ajaxpro.2"/>
</Httphandlers>
</System. Web>
</Configuration> string 7

Ajaxtest. aspx string 3

<% @ Page Language = "C #" autoeventwireup = "true" codefile = "ajaxtest. aspx. cs" inherits = "ajaxtest" %>

String 3

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

String 4

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title> string 5

</Head> string 1

<Body>
<Script language = "JavaScript" type = "text/JavaScript">
Function arearesult ()
{
VaR area = Document. getelementbyid ("dropdownlist1 ");
// Alert (area. value );
Ajaxtest. getcitylist (area. Value, get_city_result_callback );
}
Function get_city_result_callback (response)
{
If (response. value! = NULL)
{
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]. Name;
VaR id = Ds. Tables [0]. Rows [I]. ID;
Document. All ("dropdownlist2"). Options. Add (New Option (name, ID ));
}
// Document. All ("textbox1"). value = "";
}
}
Return
} String 1

</SCRIPT>
<Form ID = "form1" runat = "server">
& Nbsp;
<Asp: dropdownlist id = "dropdownlist1" runat = "server">
</ASP: dropdownlist>
<Asp: dropdownlist id = "dropdownlist2" runat = "server">
</ASP: dropdownlist> & nbsp;
<Br/>
</Form>
</Body>
</Html>

String 7

Ajaxtest. CS

String 3

Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
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 meetweb;
Public partial class ajaxtest: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Ajaxpro. Utility. registertypeforajax (typeof (ajaxtest ));
If (! Page. ispostback)
{
Binddata ();

String 7

}
}
Private void binddata ()
{
Dataset DS = new dataset ();
String SQL = "select ID, name from test ";
Try
{
DS = getdataset (SQL, "test ");
This. dropdownlist1.datasource = Ds. Tables [0];
This. dropdownlist1.datatextfield = "name ";
This. dropdownlist1.datavaluefield = "ID ";
This. dropdownlist1.databind ();

String 4

This. dropdownlist1.attributes. Add ("onclick", "arearesult ();");
}
Catch (exception ex)
{
Response. Write (ex. Message );
}
} String 6

Public static dataset getdataset (string SQL, string aa)
{
Meetweb. sqldatabase A = new meetweb. sqldatabase ("Server = localhost \ pmserver; uid = sa; Pwd = sa; database = test ");
Dataset DS = new dataset ();
DS = A. createset (SQL, AA );
Return Ds;
} String 9

[Ajaxpro. ajaxmethod]
Public dataset getcitylist (int id)
{
String SQL = "Select name from test where id = '" + ID + "'";
Return getdataset (SQL, "test ");
}

String 4

} String 1

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.