ASP.NET brings us a programming mechanism for event models, which makes we put all the tasks on the server, which is a small change, in fact, this is not a problem, but we can't stand it, if we Changing the content page in an input box To refresh, change the DROPDOWNLIST selection requires that another DropDownList needs to be refreshed, it is really depressed. Below I will describe an original method, which is why it is because this approach is already before asp.net, I don't have to describe the relationship between these two, we have to say today. How do you not refresh the page to update DropDownList, which is designed to throw bricks. In fact, use this method to achieve many applications that do not refresh the webpage and the background interaction. If you don't say anything, look at our example, first we need one Place two DROPDOWNLIST pages, if it is called WebForm2.aspx, the code of the page is as follows:
http://schemas.microsoft.com/intellisense/ie5 "name =" vs_targetschema ">
There are two DROPDOWNLISTs and a js script in the page, which can be written directly on the page. You can also write in the background on the regeist to the page (the latter is more flexible) This page of the background code is as follows, write inside Page_Load the following code: if (this.IsPostBack!) {SqlConnection con = new SqlConnection ( "server = localhost; database = pubs; uid = sa; pwd = sa;"); SqlDataAdapter da = new SqlDataAdapter ( "select state from authors group by state ", con); DataSet ds = new DataSet (); this.DropDownList1.DataTextField =" State "; this.DropDownList1.DataValueField =" State "; this.DropDownList1.DataBind (); this.DropDownList1.Attributes.Add ("OnChange", "" "" "") ");} I have done two things in the code: 1, help one of these DropDownList (you can also bind two One). 2. Specify the client script of the control. Below we will introduce the above JS code, first get the DorpdownList object to be connected on the page, clear his options, create two client objects OHTTPREQ and ODOC objects, one of the responsible requests to receive the response results, We send the user selected to the page called Webform6.aspx, which will process this request and return a response. The result of the response is an XML file, which is later introduced in WebForm6.aspx. We use the result of the load using loadXML method LOAD to the ODoc object, and then you can use the SelectNodes method to get all the CITY node, then loop these nodes to create an Option object in the client, and finally put these Option object Add to DropdWonList2.
Let's take a look at what WebFowm6.aspx has done something. The HTML page of this page is an unsearable page that includes <@Page> instructions, the background of the background is as follows: Private Void Page_Load (Object Sender, System. Eventargs e) {// put user code to initialize the page head f ("state"]! = Null) {string state = this.request ["state"]. ToString (); sqlconnection con = New SqlConnection ("Server = localhost; database = pubs; uid = sa; pwd = sa;"); sqldataadapter Da = new SqlDataAdapter ("Select City from authors where state = ' state "' ", etc; DataSet DS = New DataSet ( "CITY"); 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 ();} This method gets the user selected by the STATE to get a DataSet object after query, using the object's WriteXML method to directly Write to Response.OutputStream and passed to the client, the client's LOAD method passes an XML string by result = ohttpreq.responseText; sentence to a XML string, and finally resolve the string. This method can achieve no refreshed linkage DropdownList, data is obtained from the background database, I hope that the role of the brick introduction, what opinions or views have any opinions or opinions on the article, can send me an email or give me in 9cbs Keep SMS My ID is cuike519! thanks for reading! What do you have any mistakes in the text, please refer to you!