First, add this in HTML. This function must be implemented using Ajax.
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
Then add textbox and some autocompleteextender. Targetcontrolid must be the same as the textbox ID.
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:TextBox ID="tex_dwmc" runat="server" Visible="false"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
TargetControlID="tex_dwmc"
ServiceMethod="GetCompletionList"
CompletionSetCount="10"
MinimumPrefixLength="1"
CompletionInterval="100" EnableCaching="true" UseContextKey="True">
</cc1:AutoCompleteExtender>
</div>
Add in the background.
# Region drop-down list
[System. Web. Services. webmethodattribute (),
System. Web. Script. Services. scriptmethodattribute ()]
Public static string [] getcompletionlist (string prefixtext, int count,
String contextkey)
{
String [] DW = {"rent", "idle", "borrow "};
List <string> findcity = new list <string> (count );
Int J = 0; int K = 0;
While (k <DW. Length & J <count)
{
String pre = DW [K]. substring (0, prefixtext. Length). tolower ();
If (PRE. Equals (prefixtext. tolower ()))
{
Findcity. Add (DW [K]. tostring ());
J ++;
}
K ++;
}
Return findcity. toarray ();
}
# Endregion
String [] DW = {"rent", "idle", "borrow"}; something you want to interact.
The following describes how to select data from the database and then perform the association function.
# Region drop-down list
[System. Web. Services. webmethodattribute (),
System. Web. Script. Services. scriptmethodattribute ()]
// Private oracleconnection conn;
Public static string [] getcompletionlist (string prefixtext, int count,
String contextkey)
{
String SQL = "select distinct zcsyzk from fw_jcxxb ";
Datatable DTT = oraclehelper. executedataset (New oracleconnection (configmanager. connectionstring), commandtype. Text, SQL). Tables [0];
List <string> findcity = new list <string> (count );
Int J = 0; int K = 0;
While (k <DTT. Rows. Count & J <count)
{
For (k = 0; k <DTT. Rows. Count; k ++)
{
String pre = DTT. Rows [k] [0]. tostring (). substring (0, prefixtext. Length). tolower ();
If (PRE. Equals (prefixtext. tolower ()))
{
Findcity. Add (DTT. Rows [k] [0]. tostring ());
J ++;
}
}
}
Return findcity. toarray ();
}
# Endregion
If the page is fixed, that is to say, there is no scroll bar similar, you can use textbox + Div to achieve input and Lenovo in a dropdownlist similar to the function, using absolute position positioning.
In HTML .......
<% @ Register Assembly = "ajaxcontroltoolkit" namespace = "ajaxcontroltoolkit" tagprefix = "PC3" %> and this is an Ajax reference ..
function dingwei()
{
var dd = document.getElementById("ddl_dwmc");
VaR T = dd. offsettop;
VaR L = dd. offsetleft;
While (DD = dd. offsetparent)
{T + = dd. offsettop;
L + = dd. offsetleft;
}
VaR x = Document. getelementbyid ("tex_dwmc ");
Var y = Document. getelementbyid ("divshims ");
X. style. Position = "absolute ";
Y. style. Position = "absolute ";
X. style. Top = T;
Y. style. Top = T;
X. style. Left = L;
Y. style. Left = L;
}
<% -- Onload = "dingwei ()" In Boday calls JS -- %>
<Body onload = "dingwei ()">
Added the textbox and dropdownlist to put an IFRAME for positioning, so that the textbox is displayed on the dropdownlist to implement the input function.
<Asp: dropdownlist id = "ddl_dwmc" runat = "server" autopostback = "true"
Width = "170px" onselectedindexchanged = "ddl_dwmc_selectedindexchanged1">
<Asp: listitem> </ASP: listitem>
<Asp: listitem> apricot 10 joint station </ASP: listitem>
<Asp: listitem> xingba joint station </ASP: listitem>
</ASP: dropdownlist>
<Div>
<Asp: scriptmanager id = "scriptmanager1" runat = "server"/>
<IFRAME id = "divshims" scrolling = "no" frameborder = "0" style = "position: absolute;" Height = "23" width = "150"> </iframe>
<Asp: textbox id = "tex_dwmc" runat = "server" style = "position: absolute;"> </ASP: textbox>
<C0: autocompleteextender id = "autocompleteextender1" runat = "server" targetcontrolid = "tex_dwmc"
Servicemethod = "getcompletionlist" completionsetcount = "10" minimumprefixlength = "1"
Completioninterval = "100" enablecaching = "true" usecontextkey = "true">
</PC3: autocompleteextender>
</Div>
Background ....
# Region drop-down list
[System. Web. Services. webmethodattribute (),
System. Web. Script. Services. scriptmethodattribute ()]
Public static string [] getcompletionlist (string prefixtext, int count,
String contextkey)
{
String [] DW = {"Xingshi Union Station", "xingba Union Station "};
List <string> findcity = new list <string> (count );
Int J = 0; int K = 0;
While (k <DW. Length & J <count)
{
String pre = DW [K]. substring (0, prefixtext. Length). tolower ();
If (PRE. Equals (prefixtext. tolower ()))
{
Findcity. Add (DW [K]. tostring ());
J ++;
}
K ++;
}
Return findcity. toarray ();
}
# Endregion
Protected void ddl_dwmc_selectedindexchanged1 (Object sender, eventargs E)
{
Tex_dwmc.text = ddl_dwmc.selectedvalue; // assign the dropdownlist value to textbox.
}
: