通过键入3letters获取自动填充文本框 [英] get autopopulate textbox by typing 3letters
本文介绍了通过键入3letters获取自动填充文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过输入3letters来自动填充文本框...怎么做?
请帮帮我...
I wanna autopopulate textbox by typing 3letters...how to do this?
please help me out...
推荐答案
将ajax自动完成添加到文本框
Add ajax autocomplete to text box
<asp:autocompleteextender id="AutoCompleteExtender1" xmlns:asp="#unknown">
runat="server"
TargetControlID="txtCity"
MinimumPrefixLength="3"
EnableCaching="true"
CompletionSetCount="1"
CompletionInterval="1000"
ServiceMethod="GetCity"
</asp:autocompleteextender>
将此代码写在页面后面的代码中
write this code in code behind page
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetListofCountries(string prefixText)
{
using (SqlConnection sqlconn = new SqlConnection("Data Source=.;Initial Catalog=hotel;Integrated Security=True"))
{
sqlconn.Open();
SqlCommand cmd = new SqlCommand("select Country from country where Country like '" + prefixText + "%' ", sqlconn);
cmd.Parameters.AddWithValue("@Country", 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]["country"].ToString());
}
return CountryNames;
}
}
编写代码以使数据自动完成。
write a code to get data to auto complete.
< script type =text / javascript>
<script type="text/javascript">
(function(){
(function() {
这篇关于通过键入3letters获取自动填充文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文