2016-03-29 17 views
0

bu benim cs sayfaveri tablosuyla kullanırken ajax otomatik tamamlama uzatıcı benim kod çalışmıyor

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; 
} 
} 

bu

sınıf-benim bağlantıdır .aspx kod

<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> 

olduğunu

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; 
    } 
} 

benim saklı yordam

ALTER procedure [dbo].[AutoComplete] 
(
@topic nvarchar(20) 
) 
as 
begin 
select distinct Topic from Tutorials where Topic like @topic + '%' 
end 

Otomatik tamamlama genişletici çalışmıyor. prosedür sql sunucusunda iyi çalışıyor! Lütfen bana yardım et. Ne hata yaptığımı bilmiyorum. Şimdiden teşekkürler!

+0

kurulur? – Webruster

+0

Bunu nasıl uygulayacağımı bilmiyorum? –

+0

, bu yönteme hata ayıklama noktası mıdır? – Webruster

cevap

0

deneyin aşağıdaki gibi GetCompletionlist değiştirebilir ve ayrıca nerede getcompletionlist için sayımını geçiyoruz CompletionInterval="0"

[System.Web.Script.Services.ScriptMethod] 
    [System.Web.Services.WebMethod] 
    public static List<string> GetCompletionList(string prefixText, int count) 
    { 
     List<string> Topics = new List<string>(); 
     ConnectionClass cl = new ConnectionClass(); 
     DataTable dt = cl.AutoComplete(prefixText); 
      int i; 
     for (i = 0; i < dt.Rows.Count; i++) 
      { 
       Topics.Add(dt.Rows[i]["ColumnName"].ToString());//Try to give the column name of the resultset from the datatable 
      } 


     return Topics; 
} 
+0

Bana StoredProcedure –

+0

@SharaRizvi Webruster çalışmıyor – Webruster

+0

gösterebilir i ekledi Sorunuzun saklı yordam eklemem gerekiyor ama ben belirtti –

İlgili konular