Next, let's talk about N Asp.net dropdownlists for refreshing animations.

Source: Internet
Author: User

Let's talk about N Asp.net dropdownlist brushless New Linkage menus, sacrifice N-1 aspx to achieve automatic update mechanism, to avoid refreshing flashing !!

The following code can be used, or you can implement a multi-level menu ....

<Script language = "JavaScript">
Function load (state)
{
VaR drp2 = Document. getelementbyid ("dropdownlist2 ");
For (VAR I = 0; I <= drp2.options. Length-1; I ++)
{
Drp2.remove (I );
}
VaR ohttpreq = new activexobject ("msxml2.xmlhttp"); // send a request
VaR odoc = new activexobject ("msxml2.domdocument"); // response result
VaR state = Document. getelementbyid ("dropdownlist1"). value;
Ohttpreq. Open ("Post", "webform2.aspx? State = "+ state, false );
Ohttpreq. Send ("");
Result = ohttpreq. responsetext;
Odoc. loadxml (result );

// Items = odoc. selectnodes ("// city/table ");
Items = odoc. selectnodes ("// address/table ");
For (VAR item = items. nextnode (); item = items. nextnode ())
{
VaR city = item. selectsinglenode ("// address"). nodetypedvalue;
VaR newoption = Document. createelement ("option ");
Newoption. Text = city;
Newoption. value = city;
Drp2.options. Add (newoption );
}
}
</SCRIPT>

======================================

Webform1.aspx

Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
If (! Ispostback)
{
Sqlconnection con = new sqlconnection ("packet size = 4096; user id = sa; Data Source = server; persist Security info = false; initial catalog = pubs ");
Sqldataadapter da = new sqldataadapter ("select state from authors group by State", con );
Dataset DS = new dataset ("state ");
Da. Fill (DS );
This. dropdownlist1.datasource = Ds. Tables [0];
This. dropdownlist1.datatextfield = "state ";
This. dropdownlist1.datavaluefield = "state ";
This. dropdownlist1.databind ();
This. dropdownlist1.attributes. Add ("onchange", "load ()");
// Dropdownlist1.
}

}

Webform2.aspx

Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
If (this. request ["state"]! = NULL)
{
String state = This. request ["state"]. tostring ();
Sqlconnection con = new sqlconnection ("packet size = 4096; user id = sa; Data Source = server; persist Security info = false; initial catalog = pubs ");
Sqldataadapter da = new sqldataadapter ("select address from authors where State = '" + state + "'", con );
Dataset DS = new dataset ("Address ");
Da. Fill (DS );
Xmltextwriter writer = new xmltextwriter (response. outputstream, response. contentencoding );
Writer. Formatting = formatting. indented;
Writer. indentation = 4;
Writer. indentchar = '';
DS. writexml (writer );
Writer. Flush ();
Response. End ();
Writer. Close ();
}
}

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.