Function: Enter content in TextBox, dynamically from the database blurry query to the drop-down box for selection 1. Create an ASPX page, HTML code
<
HTML
>
<
HEAD
>
<
Title
>
Webform1
Title
>
<
Script
Language
= "JavaScript"
>
// City ------------------------------ Function CityResult () {var city = document.getlementByid ("TextBox1"); WebForm1.GetCityList (city.value, get_city_Result_CallBack);} function get_city_Result_CallBack (response) {if (! response.value = null) {// debugger;. document.getElementById ( "DropDownList1") style.display = "block"; document .getelementByid ("DropDownList1"). Length = 0; var DS = response.value; if (ds! = null && typeof (ds) == "Object" && Ds.tables! = null) {for (var i = 0 I Province.Options [pindex] .text; document.getlementBYID ("<% = textbox1.clientID%>"). InnerText = PTEXT;} Script > HEAD > < Body > < FORM id = "Form1" Method = "POST" Runat = "Server" > < ASP: TEXTBOX Id = "TextBox1" Runat = "Server" > ASP: TEXTBOX > < Br > < ASP: DropDownList Id = "DROPDOWNLIST1" Runat = "Server" Width = "192px" Style = "Display: none" > ASP: DropDownList > FORM > Body > HTML > 2.CS code 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 Ajaxselect {/ ** //// } #Endregion GetDataSet # region GetDataSet public static DataSet GetDataSet (string sql) {string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings [ "ConnectionString"]; SqlDataAdapter sda = new SqlDataAdapter (sql, ConnectionString); DataSet ds = new DataSet () SDA.FILL (DS); Return DS;} #ENDREGON}} 3. Source code download 4. Database script Create TABLE [ DBO ] . [ CITY ] ( [ id ] [ int ] NOT NULL , [ CityID ] [ nvarchar ] ( 6 COLLATE_PRC_CI_AS NULL , [ CITY ] [ nvarchar ] ( 50 COLLATE_PRC_CI_AS NULL , [ Father ] [ nvarchar ] ( 6 COLLATE_PRC_CI_AS NULL , Constraint [ PK_CITY ] Primary Key Clustered ( [ id ] ASC ) WITH (Ignore_Dup_Key = Off ) On [ Primary ] ) On [ Primary ]