Asp.net dropdownlist: no refreshing!

Source: Internet
Author: User
<Title> webform2 </title>

<Script language = 'javascript '>
Function load (){
VaR drp2 = Document. getelementbyid ("dropdownlist2 ");
Drp2.innertext = "";
For (VAR I = 0; I <= drp2.options. Length-1; I ++ ){
Drp2.remove (I );
}
VaR drp3 = Document. getelementbyid ("dropdownlist3 ");
For (VAR I = 0; I <= drp3.options. Length-1; I ++ ){
Drp3.remove (I );
}
VaR XMLHTTP = new activexobject ("msxml2.xmlhttp ");
VaR odoc = new activexobject ("msxml2.domdocument ");
VaR state = Document. getelementbyid ("dropdownlist1"). value;
XMLHTTP. Open ("Post", "webform1.aspx? Id = "+ state, false );
XMLHTTP. Send ("");
VaR res = odoc. loadxml (XMLHTTP. responsetext );
VaR naitems = odoc. selectnodes ("// market/table/maname ");
VaR iditems = odoc. selectnodes ("// market/table/maid ");
VaR item;
VaR ID;
For (item = naitems. nextnode (), id = iditems. nextnode (); item & ID; item = naitems. nextnode (), id = iditems. nextnode ()){
VaR nastr = item. nodetypedvalue;
VaR idstr = ID. nodetypedvalue;
VaR newoption = Document. createelement ("option ");
Newoption. Text = nastr;
Newoption. value = idstr;


Drp2.options. Add (newoption );
}
Load2 ();

}
Function load2 (){
VaR drp2 = Document. getelementbyid ("dropdownlist3 ");
Drp2.innertext = "";
For (VAR I = 0; I <= drp2.options. Length-1; I ++ ){
Drp2.remove (I );
}
VaR XMLHTTP = new activexobject ("msxml2.xmlhttp ");
VaR odoc = new activexobject ("msxml2.domdocument ");
VaR state = Document. getelementbyid ("dropdownlist2"). value;
XMLHTTP. Open ("Post", "webform3.aspx? Id = "+ state, false );
XMLHTTP. Send ("");
VaR res = odoc. loadxml (XMLHTTP. responsetext );
VaR naitems = odoc. selectnodes ("// market/table/maname ");
VaR iditems = odoc. selectnodes ("// market/table/maid ");
VaR item;
VaR ID;
For (item = naitems. nextnode (), id = iditems. nextnode (); item & ID; item = naitems. nextnode (), id = iditems. nextnode ()){
VaR nastr = item. nodetypedvalue;
VaR idstr = ID. nodetypedvalue;
VaR newoption = Document. createelement ("option ");
Newoption. Text = nastr;
Newoption. value = idstr;


Drp2.options. Add (newoption );
}

}
</SCRIPT>
</Head>
<Body ms_positioning = "gridlayout" onLoad = "load ()">
<Form ID = "form1" method = "Post" runat = "server">
<Asp: dropdownlist id = "dropdownlist1" runat = "server"> </ASP: dropdownlist>
<Asp: dropdownlist id = "dropdownlist2" runat = "server"> </ASP: dropdownlist>
<Asp: dropdownlist id = "dropdownlist3" runat = "server"> </ASP: dropdownlist>
</Form>
</Body>
</Html>
-----------------------
Namespace dropdown
{
/// <Summary>
/// Summary of webform2.
/// </Summary>
Public class webform2: system. Web. UI. Page
{
Protected system. Web. UI. webcontrols. dropdownlist dropdownlist1;
Protected system. Web. UI. webcontrols. dropdownlist dropdownlist3;
Protected system. Web. UI. webcontrols. dropdownlist dropdownlist2;
 
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
If (! This. ispostback)
{
Sqlconnection con = new sqlconnection ("Server = localhost; database = star; uid = sa; Pwd = ");
Sqldataadapter da = new sqldataadapter ("select maid, maname from tabmarket where macls = 0", con );
Dataset DS = new dataset ();
Da. Fill (DS, "op ");
This. dropdownlist1.datasource = Ds. Tables [0];
This. dropdownlist1.datatextfield = "maname ";
This. dropdownlist1.datavaluefield = "maid ";
This. dropdownlist1.databind ();
This. dropdownlist1.attributes. Add ("onchange", "load ()");
This. dropdownlist2.attributes. Add ("onchange", "load2 ()");
}

}

}
}
-----------------------
Public class webform1: system. Web. UI. Page
{
 
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
// Put user code to initialize the page here
// If (this. request ["state"]! = NULL)
//{
String id = This. request ["ID"];
Sqlconnection con = new sqlconnection ("Server = localhost; database = star; uid = sa; Pwd = ;");
Sqldataadapter da = new sqldataadapter ("select maname, maid from tabmarket where maparent = @ ID and mast = 1", con );
Da. selectcommand. Parameters. Add ("@ ID", ID );
Dataset DS = new dataset ("market ");
Da. Fill (DS );

DS. writexml (response. outputstream );
Response. Flush ();
Response. End ();

//}
}
}
-----------------------------
Public class webform3: system. Web. UI. Page
{
Private void page_load (Object sender, system. eventargs E)
{
// Place user code here to initialize the page
String id = request ["ID"];
Sqlconnection con = new sqlconnection ("Server = localhost; database = star; uid = sa; Pwd = ;");
Sqldataadapter da = new sqldataadapter ("select maname, maid from tabmarket where maparent = @ ID and mast = 1", con );
Da. selectcommand. Parameters. Add ("@ ID", ID );
Dataset DS = new dataset ("market ");
Da. Fill (DS );

DS. writexml (response. outputstream );
Response. Flush ();
Response. End ();
}
}
------------------

 

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.