我对C Sharp非常陌生。在我的项目中,我设计了一个搜索页面,在那里我使用AJAX Control Auto Extender的文本框,我使用Web服务填充文本框(这是我第一次使用Web服务,我不知道是什么当用户在文本框中键入单词时,将使用Web服务)。当我运行我的程序并输入Word时,我没有正确指定所有内容。带Web服务的AJAX Auto Complete Extender
这个问题可能看起来像一个重复问题,但我没有看到许多博客,看到很多博客与在那里显示的例子,但没有结果。有人帮我请,
我的Web服务代码,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using SubSonic;
using DataAccessLayer;
using System.Web.Configuration;
using System.Web.Services.Protocols;
using System.Xml.Linq;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class Search : System.Web.Services.WebService
{
public void Autocomplete()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string[] GetCompletionList(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
DataTable dt = GetRecords(prefixText);
List<string> items = new List<string>(count);
for (int i = 0; i < dt.Rows.Count; i++)
{
string strName = dt.Rows[i][0].ToString();
items.Add(strName);
}
return items.ToArray();
}
public DataTable GetRecords(string strName)
{
string QueryString;
QueryString = System.Configuration.ConfigurationManager.ConnectionStrings ["IUMSNXG"].ToString();
using (SqlConnection obj_SqlConnection = new SqlConnection(QueryString))
{
using (SqlCommand obj_Sqlcommand = new SqlCommand())
{
obj_Sqlcommand.CommandType = CommandType.StoredProcedure;
obj_Sqlcommand.CommandText = "LRS_SP_CBFM_Sel";
obj_Sqlcommand.Connection = obj_SqlConnection;
obj_SqlConnection.Open();
obj_Sqlcommand.Parameters.AddWithValue("@animalCode", strName);
SqlDataAdapter dt = new SqlDataAdapter(obj_Sqlcommand);
DataSet ds=new DataSet();
dt.Fill(ds);
obj_SqlConnection.Close();
return ds.Tables[0];
}
}
}
}
我的AJAX工具脚本管理是
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/Search.asmx" />
</Services>
</asp:ToolkitScriptManager>
我的文本框,并自动完成扩展是,
<Anthem:TextBox ID="srchtxt" runat="server" AutoUpdateAfterCallBack="true"
Height="19px" Width="200px"></Anthem:TextBox>
<asp:AutoCompleteExtender ID="srchtxt_AutoCompleteExtender" runat="server"
CompletionInterval="100" DelimiterCharacters="" Enabled="True"
ServicePath="~/Search.asmx"
TargetControlID="srchtxt" UseContextKey="True"
ServiceMethod="GetCompletionList">
</asp:AutoCompleteExtender>
我已经发布了使用jquery自动完成 - http://deepumi.wordpress.com/2011/03/25/jquery-auto-completion-with -multiple-fileds-in-asp-net -c/ –
@ Deepu在我的地方WordPress的网站被阻止如果你不介意可以在这里发帖? – Rajesh
你可以分享你的电子邮件地址..我可以给你的工作代码 –