dies ASPX Codemeinen Code für Ajax Autocomplete-Extender funktioniert nicht, wenn sie mit Datentabelle mit
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods = "true"></asp:ScriptManager>
<asp:TextBox ID="SearchTextBox" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ServiceMethod="GetCompletionList" MinimumPrefixLength="1"
CompletionInterval="10" EnableCaching="false" CompletionSetCount="1" TargetControlID="SearchTextBox"
ID="AutoCompleteExtender1" runat="server" FirstRowSelected="false">
</ajaxToolkit:AutoCompleteExtender>
</div>
diese Seite meine cs ist
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class UserMasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Script.Services.ScriptMethod]
[System.Web.Services.WebMethod]
public static List<string> GetCompletionList(string prefixText, int count)
{
ConnectionClass cl = new ConnectionClass();
DataTable dt = cl.AutoComplete(prefixText);
List<string> Topics = new List<string>();
using (dt)
{
int r = dt.Rows.Count;
while (r > 0)
{
Topics.Add(dt.Rows[r].ItemArray[0].ToString());
r--;
}
}
return Topics;
}
}
dies meine Verbindung ist Klassen-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
/// <summary>
/// Summary description for Class1
/// </summary>
public class ConnectionClass
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader dr;
string str;
public ConnectionClass()
{
str = @"Data source=INSPIRATION\SQLEXPRESS; Initial Catalog=ComputerPedia; Integrated security= true";
}
public void establishConnection()
{
con = new SqlConnection(str);
if (con.State == ConnectionState.Closed)
con.Open();
}
public void closeConnection()
{
if (con.State == ConnectionState.Open)
con.Close();
}
public void createReaderCommand(string sql)
{
cmd = new SqlCommand(sql, con);
dr = cmd.ExecuteReader();
}
public SqlDataReader executeReaderCommand()
{
dr.Read();
return dr;
}
public DataTable AutoComplete(string topic)
{
DataTable dt = new DataTable();
dt.Columns.Add("Topic");
establishConnection();
cmd = new SqlCommand("AutoComplete", con);
cmd.Parameters.Add("@topic", SqlDbType.NVarChar).Value = topic;
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
closeConnection();
return dt;
}
}
meine gespeicherten Prozedur
ALTER procedure [dbo].[AutoComplete]
(
@topic nvarchar(20)
)
as
begin
select distinct Topic from Tutorials where Topic like @topic + '%'
end
mein auto complete Extender funktioniert nicht. das Verfahren funktioniert gut in SQL Server !. Bitte hilf mir. Ich weiß nicht, welchen Fehler ich gemacht habe. Danke im Voraus!
wo bist du Zählung vorbei getcompletionlist? – Webruster
ich weiß nicht, wie man das umsetzt? –
ist Debug-Punkt feuern zu dieser Methode? – Webruster