Asp.net| Control | refresh | no refresh
On the internet saw some no refresh of the linkage control. After the test, the display of English and the number can be, but not to display Chinese, and then down from the Internet down the file made a change, made a provincial and municipal linkage control. Share it for everyone. Can be displayed in Chinese.
<%@ Page language= "C #" codebehind= "Example.aspx.cs" autoeventwireup= "false" inherits= "Webs.other.Example"%>
<HTML>
<HEAD>
<title>Example</title>
<meta name= "generator" content= "Microsoft Visual Studio. NET 7.1" >
<meta name= "Code_language" content= "C #" >
<meta name= "vs_defaultClientScript" content= "JavaScript" >
<meta name= "vs_targetschema" content= "http://schemas.microsoft.com/intellisense/ie5" >
<script>
function Load (state) {
var drp2 = document.getElementById ("DropDownList2");
for (i = Drp2.length i >= 0; i--) {
Drp2.options.remove (i);
}
var ohttpreq = new ActiveXObject ("MSXML2. XMLHTTP ");
var odoc = new ActiveXObject ("MSXML2. DOMDocument ");
Ohttpreq.open ("POST", "getdata.aspx?state=" +state, false);
Ohttpreq.send ("");
result = Ohttpreq.responsetext;
Odoc.loadxml (result);
ITEMS1 = Odoc.selectnodes ("//city/table/id");
ITEMS2 = Odoc.selectnodes ("//city/table/shiname");
var itemslength=items1.length;
for (i=0;i<itemslength;i++)
Assign the class name and number of a small class to DropDownList2
{
var newoption = document.createelement ("option");
Newoption.text=items2[i].text;
Newoption.value=items1[i].text;
Drp2.options.add (newoption);
}
}
Window.onload = function () {load (' 1 ');}
</script>
</HEAD>
<body ms_positioning= "FlowLayout" >
<form id= "Form1" method= "POST" runat= "Server" >
<asp:dropdownlist id= "DropDownList1" runat= "Server" ></asp:DropDownList>
<asp:dropdownlist id= "DropDownList2" runat= "Server" ></asp:DropDownList>
<asp:textbox id= "TH" runat= "Server" ></asp:TextBox>
<asp:button id= "Button1" runat= "Server" text= "button" ></asp:Button>
</form>
</body>
</HTML>
CS Source file:
Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;
Using System.Data.SqlClient;
Namespace Webs.other
{
<summary>
Summary description of the Example.
</summary>
public class Example:System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.TextBox TH;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
private void Page_Load (object sender, System.EventArgs e)
{
Place user code here to initialize page
if (!this. IsPostBack)
{
Create a data source to load the first DropDownList, or you can load the second by default
SqlConnection con = new SqlConnection (System.Configuration.ConfigurationSettings.AppSettings.Get ("connStr1"));
SqlDataAdapter da = new SqlDataAdapter ("Select Id,shengname from Province", con);
DataSet ds = new DataSet ();
Da. Fill (DS);
This. Dropdownlist1.datasource = ds;
This. Dropdownlist1.datatextfield = "Shengname";
This. Dropdownlist1.datavaluefield = "Id";
This. Dropdownlist1.databind ();
This is a binding client event that fires the following event onchange when the first DropDownList option changes, and this event invokes a client method load ()
This. DROPDOWNLIST1.ATTRIBUTES.ADD ("onchange", "Load (this.options[this.selectedindex].value)");
}
}
#region Web Form Designer generated code
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This. Button1.Click + = new System.EventHandler (this. Button1_Click);
This. Load + = new System.EventHandler (this. Page_Load);
}
#endregion
private void Button1_Click (object sender, System.EventArgs e)
{
TH. Text=this. request.form["DropDownList2"]. ToString ();
}
}
}
GetData Source Files
Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;
Using System.Data.SqlClient;
Using System.Xml;
Using System.Configuration;
Using System.Text;
A summary description of the
namespace Webs.other
{
///<summary>
///GetData.
///</summary>
public class GetData:System.Web.UI.Page
{
private void Page_Load (object sender, System.EventArgs e)
{
//Place user code here to initialize the page
//response.write (request["state"]);
int Shengno=int. Parse (request["state"). ToString ());
sqlconnection con = new SqlConnection ( System.Configuration.ConfigurationSettings.AppSettings.Get ("ConnStr1"));
sqldataadapter da = new SqlDataAdapter ("Select Id,shiname from city where shengid=" "+shengno+" ", Con);
dataset ds = new DataSet ("City");
da. Fill (DS);
xmltextwriter writer = new XmlTextWriter (RESPONSE.OUTPUTSTREAM,ENCODING.UTF8);
writer. formatting = formatting.indented;
writer. indentation = 4;
writer. IndentChar = ';
writer. WriteStartDocument ();
ds. WriteXml (writer);
writer. Flush ();
response.end ();
writer. Close ();
}
#region Web Form Designer generated code
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This. Load + = new System.EventHandler (this. Page_Load);
}
#endregion
}
}