<Form ID = "form1" method = "Post" runat = "server">
<Asp: dropdownlist id = "dropdownlist1" runat = "server"> </ASP: dropdownlist>
<Asp: dropdownlist id = "dropdownlist2" runat = "server"> </ASP: dropdownlist>
<Script language = "JavaScript">
<! --
// Obtain data in XML format
Function xmlpost (OBJ)
{
VaR svalue = obj. value;
VaR webfileurl = "? Brc_id = "+ svalue;
VaR result = "";
VaR XMLHTTP = new activexobject ("msxml2.xmlhttp ");
XMLHTTP. Open ("Post", webfileurl, false );
XMLHTTP. Send ("");
Result = XMLHTTP. responsetext;
If (result! = "")
{
Document. All ("dropdownlist2"). Length = 0;
VaR piarray = result. Split (",");
For (VAR I = 0; I <piarray. length; I ++)
{
VaR ary1 = piarray [I]. tostring (). Split ("| ");
// Alert (ary1 [0]. tostring ());
Document. All ("dropdownlist2"). Options. Add (New Option (ary1 [1]. tostring (), ary1 [0]. tostring ()));
}
}
Else
{
Alert (result );
}
}
// -->
</SCRIPT>
</Form>
The following is the backgroundCode:
Private system. Data. oledb. oledbconnection conn;
Private datatable get_dt (string SQL)
{
String connstr = "provider = msdaora.1; Password = aqjc; user id = aqjc; Data Source = aqjc ";
This. Conn = new oledbconnection (connstr );
This. Conn. open ();
Oledbcommand myoledbcommand = new oledbcommand (SQL, this. Conn );
Oledbdataadapter mydata = new oledbdataadapter (myoledbcommand );
Dataset mydataset = new dataset ();
Try
{
Mydata. Fill (mydataset );
}
Catch (exception ex)
{
Throw ex;
}
This. Conn. Close ();
Return mydataset. Tables [0];
}
Private void page_load (Object sender, system. eventargs E)
{
String brc_id = This. Request. querystring ["brc_id"];
If (brc_id + ""! = "")
{
This. down2_bind (brc_id );
}
If (! This. ispostback)
{
This. downloadbind ();
}
}
/// <Summary>
/// Return the value required for the 2nd drop-down boxes to XMLHTTP
/// </Summary>
/// <Param name = "brc_id"> </param>
Private void down2_bind (string brc_id)
{
String mystr = "";
String SQL = "select brc_id, brc_name from asm_branch where brc_parentid = '" + brc_id + "'";
Datatable mytab = This. get_dt (SQL );
If (mytab. Rows. Count! = 0)
{
For (INT I = 0; I <mytab. Rows. Count; I ++)
{
Mystr + = "," + mytab. Rows [I] [0]. tostring () + "|" + mytab. Rows [I] [1]. tostring ();
}
Mystr = mystr. substring (1 );
}
This. response. Write (mystr );
This. response. End ();
}
/// <Summary>
/// Bind the first drop-down box
/// </Summary>
Private void downloadbind ()
{
String SQL = "select brc_id, brc_name from asm_branch where brc_level = '1 '";
Datatable mytab = This. get_dt (SQL );
This. dropdownlist1.datasource = mytab;
This. dropdownlist1.datavaluefield = "brc_id ";
This. dropdownlist1.datatextfield = "brc_name ";
This. dropdownlist1.databind ();
This. dropdownlist1.attributes. Add ("onchange", "xmlpost (this );");
}
// The following is a VB Script
<Script language = "VBScript">
<! --
'Retrieve data using XML
Function xmlpost (OBJ)
Dim svalue
Svalue = obj. Value
Dim webfileurl
Webfileurl = "? Brc_id = "+ svalue
Dim result
Set XMLHTTP = Createobject ("Microsoft. XMLHTTP ")
Call XMLHTTP. Open ("Post", webfileurl, false)
Call XMLHTTP. Send ("")
Result = XMLHTTP. responsetext
Set downlist = Document. All ("dropdownlist2 ")
If result <> "" then
Document. All ("dropdownlist2"). Length = 0
Dim piarray, ary1
Piarray = Split (result ,",")
For I = 0 to piarray. Length-1
Ary1 = Split (piarray (I), "| ")
Downlist. Length = downlist. Length + 1
Downlist. Options (downlist. Length-1). Text = ary1 (1)
Downlist. Options (downlist. Length-1). value = ary1 (0)
Next
Else
Alert (result)
End if
End Function
// -->
</SCRIPT>
Http://www.cnblogs.com/gwazy/archive/2005/05/10/152312.html
Function do_link_change (changeobj, N, jsval, jsshow)
{
If (n <0) return;
VaR E = eval ("document. All." + changeobj );
For (VAR I = E. Options. length; I>-1; I --)
E. Remove (I );
VaR show = eval (jsshow + "[" + N + "]"); // obtain the array name.
Var val = eval (jsval + "[" + N + "]");
If (Val. Length <1) return;
For (VAR I = 0; I <Val. length; I ++)
E. Options. Add (New Option (show [I], Val [I]);
}
Then you must write the corresponding JS variables on the client, such
VaR area_show = new array ();
VaR area_value = new array ();
VaR point_show = new array ();
VaR point_value = new array ();
Area_show [0] = 'guangdong ';
Area_value [0] = 510000;
Point_show [0] = new array ();
Point_value [0] = new array ();
Area_show [1] = 'guangzhou ';
Area_value [1] = 510100;
Point_show [1] = new array ();
Point_value [1] = new array ();
Point_show [1] [0] = 'tianhe ';
Point_value [1] [0] = 1;
Point_show [1] [1] = 'henan ';
Point_value [1] [1] = 1;
Point_show [1] [2] = 'train station ';
Point_value [1] [2] = 3;
Area_show [2] = 'shenzhen ';
Area_value [2] = 510200;
Point_show [2] = new array ();
Point_value [2] = new array ();
Point_show [2] [0] = 'nanshan ';
Point_value [2] [0] = 1;
Point_show [2] [1] = 'longgang ';
Point_value [2] [1] = 1;
Point_show [2] [2] = 'yantian ';
Point_value [2] [2] = 3;
Then write onchange = "do_link_change ('nspoint', this. selectedindex, 'Point _ value', 'Point _ show')" in the first dropdownlist ')"
"Npoint" is the ID of the second dropdownlist
+: Http://community.csdn.net/Expert/topic/4097/4097823.xml? Temp =. 9292414.