自动完成文本框文本,例如Google Wihtout Web服务 [英] Auto Complete Textbox text like google wihtout web services
本文介绍了自动完成文本框文本,例如Google Wihtout Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友
当我们在文本框中输入单个字符(例如google ..
)时,我只想自动完成文本框
不使用Web服务怎么办...
提前谢谢...
Pratham
解决方案
参考:
不使用Web的ASP.Net AJAX控件工具包AutoCompleteExtender服务 [ ^ ]
Ajax AutoCompleteExtender示例或示例,而无需使用网络服务 [自动完成演示 [使用ASP. NET AJAX自动完成控件 [ CodeProject答案 [ ^ ]和 CodeProject文章 [不使用Web服务的ASP.Net Ajax AutoCompleteExtender [ ^ ]
AutoCompleteExtender,其中包含来自ASPX代码的数据 [ ^ ]
CS.aspx编码----
<%@ 页面 语言 =" C#" AutoEventWireup true" CodeFile =" 继承 _ Default" %> <%@ 注册 组件 =" 命名空间 AjaxControlToolkit" TagPrefix =" < !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 过渡//EN" " http://www.w3. org/TR/xhtml1/DTD/xhtml1-transitional.dtd" < html =" http://www.w3.org/1999/xhtml" > < 头 =" 服务器" < 标题 > < /title > < /head > < 正文 > < 表单 =" form1" runat >服务器" > < div > < asp:ScriptManager ID =" runat 服务器" EnablePageMethods =" true" < /asp:ScriptManager > < asp:TextBox ID =" runat 服务器" 宽度 231px" < /asp:TextBox > < cc11:AutoCompleteExtender ServiceMethod =" MinimumPrefixLength =" 2" CompletionInterval =" 100" 启用缓存 false" CompletionSetCount =" TargetControlID =" txtContactsSearch" ID =" AutoCompleteExtender1" runat 服务器" FirstRowSelected =" < /cc11:AutoCompleteExtender > < br > < br > < /div > < /form > < /body > < /html >
Cs.aspx .........
使用系统; 使用 System.Collections.Generic; 使用 System.Web; 使用 System.Web.UI; 使用使用System.Web.UI.WebControls; 使用 System.Data.SqlClient; 使用 System.Configuration; 公共 部分 类 _Default:System.Web .UI.页面 { 受保护的 无效 Page_Load(对象发件人,EventArgs e) { } [System.Web.Script.Services.ScriptMethod()] [System.Web.Services.WebMethod] 公共 静态列表< string> SearchCustomers(字符串 prefixText, int 计数) { 使用(SqlConnection conn = 新 SqlConnection()) { conn.ConnectionString = ConfigurationManager .ConnectionStrings [" ].ConnectionString; 使用(SqlCommand cmd = 新 SqlCommand()) { cmd.CommandText = " + " ; cmd.Parameters.AddWithValue(" ,prefixText); cmd.Connection = conn; conn.Open(); List< string>客户= 新 List< string>(); 使用(SqlDataReader sdr = cmd.ExecuteReader()) { while (sdr.Read()) { customer.Add(sdr [" ].ToString()); } } conn.Close(); 回访客户; } } }
Hi friends
i just want to auto complete the text box when we entered a single character in textbox like google ..
How can it be done without using web services...
Thanks in advance...
Pratham
解决方案
Refer:
ASP.Net AJAX Control Toolkit AutoCompleteExtender without using Web Services[^]
Ajax AutoCompleteExtender example or sample without using webservice[^]
AutoComplete Demonstration[^]
Some more:
Use the ASP.NET AJAX AutoComplete Control[^]
Also have a look on CodeProject Answers[^] and CodeProject Articles[^] on same.
I think this is what you are looking for
ASP.Net Ajax AutoCompleteExtender Without Using Web Service[^]
AutoCompleteExtender with data from ASPX code behind[^]
CS.aspx Codee----
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc11" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods = "true"> </asp:ScriptManager> <asp:TextBox ID="txtContactsSearch" runat="server" Width="231px"></asp:TextBox> <cc11:AutoCompleteExtender ServiceMethod="SearchCustomers" MinimumPrefixLength="2" CompletionInterval="100" EnableCaching="false" CompletionSetCount="10" TargetControlID="txtContactsSearch" ID="AutoCompleteExtender1" runat="server" FirstRowSelected = "false"> </cc11:AutoCompleteExtender> <br /> <br /> </div> </form> </body> </html>
Cs.aspx.........
using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } [System.Web.Script.Services.ScriptMethod()] [System.Web.Services.WebMethod] 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 clientname from ssj.dbo.chq_mst where " + "clientname 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["clientname"].ToString()); } } conn.Close(); return customers; } } }
这篇关于自动完成文本框文本,例如Google Wihtout Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文