ASP.NET中的自动填充文本框 [英] Autocomplete textbox in ASP.NET
本文介绍了ASP.NET中的自动填充文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用带有多个表的ajax的自动完成文本框以及带有表名和搜索项的自动完成列表。
什么我试过了:
html代码:
i want to use auto complete textbox using ajax with the multiple tables and the list of the autocomplete with the table name and search items.
What I have tried:
html code :
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods = "true">
<asp:TextBox ID="txtContactsSearch" runat="server">
<cc1:AutoCompleteExtender ServiceMethod="SearchCustomers"
MinimumPrefixLength="2"
CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
TargetControlID="txtContactsSearch"
ID="AutoCompleteExtender1" runat="server" FirstRowSelected = "false">
C#代码:
C# code :
public static List<string> SearchCustomers(string prefixText, int count)
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager
.ConnectionStrings["constr"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select ContactName from Customers where " +
"ContactName like @SearchText + '%'";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Connection = conn;
conn.Open();
List<string> customers = new List<string>();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
customers.Add(sdr["ContactName"].ToString());
}
}
conn.Close();
return customers;
}
}
}
推荐答案
请点击以下链接获取您的帮助:
http://www.aspdotnet-suresh.com/2015/06/jquery-autocomplete-textbox-in-aspnet-with-database-example-using-csharp-vbnet.html [ ^ ]
使用ASP.Net中的AJAX PageMethods从数据库实现jQuery AutoComplete TextBox [ ^ ]
Please check these links below for your help:
http://www.aspdotnet-suresh.com/2015/06/jquery-autocomplete-textbox-in-aspnet-with-database-example-using-csharp-vbnet.html[^]
Implement jQuery AutoComplete TextBox from database using AJAX PageMethods in ASP.Net[^]
这篇关于ASP.NET中的自动填充文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文