Hello,
I've got an Ajax AutoCompleteExtender that I seem to be having trouble with. I followed a basic implementation tutorial..http://www.asp.net/ajaxlibrary/act_AutoComplete_Simple.ashx .. and I was able to populate the static string data from the code behind. I know the function is working properly. I just cannot seem to call the data from a database correctly.
I've got sqlDataSource controls on the same page I work with and they work to populate GridView controls. I just cannot seem to query my SQL compact database from the code behind. The syntax seems to be correct, according to intellisence but it simply does nothing when I start typing a search in target control.
Any Suggestions?
The control is registered in the Web.config file for all pages.
ASP for ToolkitScriptManager:
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>
ASP for AutoCompleteExtender:
<asp:TextBox ID="ClientSearch" runat="Server" Width="227px"></asp:TextBox><ajaxToolkit:AutoCompleteExtender CompletionListCssClass="AutoExtender" CompletionListItemCssClass="AutoExtenderListItem" CompletionListHighlightedItemCssClass="AutoExtenderItemHighlighted" ID="AutoCompleteExtender1" TargetControlID="ClientSearch" runat="server" ServiceMethod="GetCompletionList" MinimumPrefixLength="1" UseContextKey="True"></ajaxToolkit:AutoCompleteExtender><asp:Button ID="SearchSubmit" runat="Server" Text="Search" />
Below is were I'm stuck..I cannot seem to find a good method here to call the data from my SQL compact database...I do have a ConnectionString on the Web.config and I am able to get that same data with an SQLdatasource control..I just cannot get it with any of the code-behind methods I have tried from any tutorial..
Here is the page Code Behind (C#)
using System.Data; using System.Data.SqlClient; using System.Collections.Generic; using System.Configuration; using System; 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> GetCompletionList(string prefixText) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()); con.Open(); SqlCommand cmd = new SqlCommand("select * from Current where Name like @Name+'%'", con); cmd.Parameters.AddWithValue("@Name", prefixText); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); List<string> Names = new List<string>(); for (int i = 0; i < dt.Rows.Count; i++) { Names.Add(dt.Rows[i][1].ToString()); } return Names; } }
Here is are my Connection Strings in the Web.config
<connectionStrings><add name="ConnectionString" connectionString="Data Source=|DataDirectory|\Clients.sdf" providerName="System.Data.SqlServerCe.4.0" /><add name="ClientsEntities" connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="data source=|DataDirectory|\Clients.sdf"" providerName="System.Data.EntityClient" /></connectionStrings>
What am I doing wrong? I'm open to criticism. I'm a roast, baste me..