在文本框的焦点上查看AutoCompleteExtender [英] view AutoCompleteExtender on focus of the textbox
本文介绍了在文本框的焦点上查看AutoCompleteExtender的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本框和一个自动完成扩展程序。守则正在顺利执行。但是当我专注于文本框时,我想打开列表。
请建议。
我使用了所有这些代码。 />
< asp:TextBox ID = TextBox3 runat = server 宽度 = 268px ontextchanged = TextBox3_TextChanged AutoPostBack = true onblur = 更改(this,event) onfocus = 更改(此事件) > < / asp:TextBox >
< ajax:autocompleteextender ID = AutoCompleteExtender1 runat = < span class =code-keyword> server TargetControlID = TextBox3 MinimumPrefixLength = 1 EnableCaching = true CompletionSetCount = 1 CompletionInterval = 10 ServiceMethod = GetCountries
CompletionListCssClass = autocomplete_completionListElement < span class =code-attribute> CompletionListItemCssClass = autocomplete_listItem CompletionListHighlightedItemCssClass = autocomplete_highlightedListItem >
< / ajax:autocompleteextender >
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<串GT; GetCountries(string prefixText)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [LocalSqlServer]。ConnectionString.ToString());
con.Open();
SqlCommand cmd = new SqlCommand(select * from table1 where col1 like @id +''%'',con);
cmd.Parameters.AddWithValue(@ id,prefixText);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
List< string> CountryNames = new List< string>();
for(int i = 0; i< dt.Rows.Count; i ++)
{
CountryNames.Add(dt.Rows [i] [0] .ToString());
}
返回CountryNames;
}
请帮帮我。
我的问题是如何打开清单autocompleteextender,当我的光标聚焦文本框时。
请帮助
解决方案
<%@ Page Language = C#%>
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional。 DTD>
< script runat =server>
protected void Page_Load(object sender,EventArgs e)
{
AutoCompleteExtender1.ContextKey =ace1;
}
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string [] GetCompletionList(string prefixText ,int count,string contextKey)
{
string [] result = new string [6];
for(int i = 0; i< 6; i ++)
{
result [i] = prefixText + i.ToString();
}
返回结果;
}
< / script>
< html xmlns =http://www.w3.org/1999/xhtml>
< head id =Head1runat =server>
< title> Untitled Page< / title>
< / head>
< body>
< form id =form1runat =server>
< ajaxToolkit:ToolkitScriptManager ID =ScriptManager1runat =server/>
< div>
< asp:TextBox ID =TextBox1runat =server>< / asp:TextBox>
< ajaxToolkit:AutoCompleteExtender MinimumPrefixLength =0ID =AutoCompleteExtender1
ServiceMethod =GetCompletionListrunat =serverTargetControlID =TextBox1>
< / ajaxToolkit:AutoCompleteExtender>
< / div>
< / form>
< / body>
< / html>
您当然可以从中获得参考,例如MinimumPrefixLength =0
来源: ASP .NET论坛 [ ^ ]
I have a textbox and an autocomplete extender. The Code is executing perfectly. But I want open the list as and when I focus on the textbox.
Please suggest.
I used all these code.
<asp:TextBox ID="TextBox3" runat="server" Width="268px" ontextchanged="TextBox3_TextChanged" AutoPostBack="true" onblur="Change(this, event)" onfocus="Change(this, event)"></asp:TextBox>
<ajax:autocompleteextender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox3" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="10" ServiceMethod="GetCountries"
CompletionListCssClass="autocomplete_completionListElement" CompletionListItemCssClass="autocomplete_listItem" CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem">
</ajax:autocompleteextender>
[System.Web.Script.Services.ScriptMethod()] [System.Web.Services.WebMethod] public static List<string> GetCountries(string prefixText) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString.ToString()); con.Open(); SqlCommand cmd = new SqlCommand("select * from table1 where col1 like @id+''%''", con); cmd.Parameters.AddWithValue("@id", prefixText); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); List<string> CountryNames = new List<string>(); for (int i = 0; i < dt.Rows.Count; i++) { CountryNames.Add(dt.Rows[i][0].ToString()); } return CountryNames; }
please help me.
My question is "How to open the list of autocompleteextender, when my cursor focus the textbox".
Please help
解决方案
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { AutoCompleteExtender1.ContextKey = "ace1"; } [System.Web.Services.WebMethod] [System.Web.Script.Services.ScriptMethod] public static string[] GetCompletionList(string prefixText, int count, string contextKey) { string[] result = new string[6]; for (int i = 0; i < 6; i++) { result[i] = prefixText + i.ToString(); } return result; } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" /> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <ajaxToolkit:AutoCompleteExtender MinimumPrefixLength="0" ID="AutoCompleteExtender1" ServiceMethod="GetCompletionList" runat="server" TargetControlID="TextBox1"> </ajaxToolkit:AutoCompleteExtender> </div> </form> </body> </html>
You can certainly have a reference from it, likeMinimumPrefixLength="0"
Source : ASP .NET Forum[^]
这篇关于在文本框的焦点上查看AutoCompleteExtender的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文