Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey,

I'm Working with ASP.NET.

I want to use AutoCompleteExtender and I've written a complete code but till m not getting the result. I m not able to find the the syntax problem. because program runs successfully without any error.
Can anybody plz help me out?
ASP.NET
<asp:TextBox ID="txt_search" runat="server" Width="250px"> 
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
 <asp:AutoCompleteExtender CompletionInterval="100" Enabled="true" CompletionSetCount="1" MinimumPrefixLength="1" TargetControlID="txt_search" ID="AutoSuggestion" runat="server" ServicePath="~/Lib_BookSearch.asmx" ServiceMethod="AutoDescription">

C#
[WebMethod]
    public string[] AutoDescription(string pretext)
    {
        SqlConnection cn=new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\khushboo\sem 6\running NEW on C59\LIVE\App_Data\libdata.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd = new SqlCommand("select des from Table1 where des LIKE '%" + pretext + "%'", cn);
        cn.Open();
        cmd.Parameters.AddWithValue("@pretext", pretext);
        cmd.ExecuteNonQuery();
        
        cn.Close();
        SqlDataAdapter adp = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        adp.SelectCommand.Parameters.Add("@pretext", SqlDbType.VarChar, 50).Value = pretext + "%";
        adp.Fill(ds);
        string[] arr = new string[ds.Tables[0].Rows.Count];
        for (int i = 0; i < arr.Length; i++)
            arr[i] = ds.Tables[0].Rows[i][0].ToString();
        return arr;
    }
Posted
Updated 16-Mar-12 0:19am
v4
Comments
Prasad_Kulkarni 13-Mar-12 0:17am    
post your code so we can find solution quickly..
khushi mamtora 13-Mar-12 1:52am    
There is my code Can you help now?

Update your command and use this:
C#
SqlCommand cmd = new SqlCommand("select des from Table1 where des LIKE '%" + pretext + "%'", cn);
 
Share this answer
 
Comments
khushi mamtora 13-Mar-12 1:27am    
I did it. Bus Still not working sir!
Nothing happens when i write in text box!
Prasad_Kulkarni 13-Mar-12 1:51am    
check you db, have u inserted data over there
khushi mamtora 13-Mar-12 1:59am    
Yes, I have! I checked it 2 times!
data is in currect formate!
i tried it with new application also.
Refer the below article, which gives step by step process. It will help you to track thing where it goes wrong. Ref: http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx[^]
 
Share this answer
 
Comments
khushi mamtora 13-Mar-12 1:13am    
sir, its not working. Do I send you my code?
M not able to find error.
Would you be able to?


<asp:TextBox ID="txt_search" runat="server" Width="250px">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">

<asp:AutoCompleteExtender CompletionInterval="100" Enabled="true" CompletionSetCount="1"
MinimumPrefixLength="1" TargetControlID="txt_search" ID="AutoSuggestion" runat="server"
ServicePath="~/Lib_BookSearch.asmx" ServiceMethod="AutoDescription">


public string[] AutoDescription(string pretext)
{
SqlConnection cn=new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\khushboo\sem 6\running NEW on C59\LIVE\App_Data\libdata.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd = new SqlCommand("select des from Table1 where des LIKE @pretext", cn);
cn.Open();
cmd.Parameters.AddWithValue("@pretext", pretext);
cmd.ExecuteNonQuery();

cn.Close();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.SelectCommand.Parameters.Add("@pretext", SqlDbType.VarChar, 50).Value = pretext + "%";
adp.Fill(ds);
string[] arr = new string[ds.Tables[0].Rows.Count];
for (int i = 0; i < arr.Length; i++)
arr[i] = ds.Tables[0].Rows[i][0].ToString();
return arr;
}
C#
[System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]
    public static List<string> SearchCustodian(string prefixText, int count)              //This service is used to Search Custodian
    {
        using (SqlConnection conn = new SqlConnection())
        {
            conn.ConnectionString = ConfigurationManager             .ConnectionStrings["connStringForAutoComplete"].ConnectionString;
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = "select des from Table1 where des like '%'+ @SearchText + '%'";
                cmd.Parameters.AddWithValue("@SearchText", prefixText);
                cmd.Connection = conn;
                conn.Open();
                List<string> vcName = new List<string>();
                using (SqlDataReader sdr = cmd.ExecuteReader())
                {
                    while (sdr.Read())
                    {
                        vcName.Add(sdr["des"].ToString();
                    }
                }
                conn.Close();
                return vcName;
            }

        }
    }



XML
<ajaxToolkit:AutoCompleteExtender ID="aceAssetNumber" runat="server" TargetControlID="txtAssetNumber"
                                                    BehaviorID="testAutoComplete" Enabled="True" OnClientPopulated="Test" DelimiterCharacters="" EnableCaching="False" CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" CompletionListItemCssClass="autocomplete_listItem" CompletionListCssClass="autocomplete_completionListElement" ServicePath="" ServiceMethod="SearchCustodian" CompletionListElementID="listPlacement" CompletionInterval="0" MinimumPrefixLength="1">                                             </ajaxToolkit:AutoCompleteExtender>



and css class


<pre lang="cs">.autocomplete_completionListElement {
BORDER-RIGHT: buttonshadow 1px solid; BORDER-TOP: buttonshadow 1px solid; FONT-SIZE: 8pt; VISIBILITY: hidden; MARGIN: 0px; OVERFLOW: auto; BORDER-LEFT: buttonshadow 1px solid; COLOR: windowtext; BORDER-BOTTOM: buttonshadow 1px solid; FONT-FAMILY: Verdana; LIST-STYLE-TYPE: none; TEXT-ALIGN: left;max-height:200px;min-height:0px;
}
.autocomplete_highlightedListItem {
PADDING-RIGHT: 1px; PADDING-LEFT: 1px; PADDING-BOTTOM: 1px; COLOR: black; PADDING-TOP: 1px; BACKGROUND-COLOR: #ffff99
}
.autocomplete_listItem {
PADDING-RIGHT: 1px; PADDING-LEFT: 1px; PADDING-BOTTOM: 1px; COLOR: windowtext; PADDING-TOP: 1px; BACKGROUND-COLOR: window
}</pre>



try to implement like that definatly it will work khushboo
and make your connectionstring in webconfig like that....

<connectionstrings>
<add name="connStringForAutoComplete" connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\khushboo\sem 6\running NEW on C59\LIVE\App_Data\libdata.mdf;Integrated Security=True;User Instance=True" />
<connectionstrings></connectionstrings></connectionstrings>
 
Share this answer
 
Comments
khushi mamtora 13-Mar-12 3:26am    
its still not working!
nothing happens when I enter text in textbox.
infosoftsaranya 16-Mar-12 6:24am    
connectionstrings>
<add name="connStringForAutoComplete" connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\khushboo\sem 6\running NEW on C59\LIVE\App_Data\libdata.mdf;Integrated Security=True;User Instance=True">
<connectionstrings>
infosoftsaranya 16-Mar-12 6:24am    
connectionstrings>
<add name="connStringForAutoComplete" connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\khushboo\sem 6\running NEW on C59\LIVE\App_Data\libdata.mdf;Integrated Security=True;User Instance=True">
<connectionstrings>
debug the service method and please check it khushboo you getting error while debugging the service and also make it textbox autopostback property true
 
Share this answer
 
Comments
khushi mamtora 14-Mar-12 0:55am    
the cursor is not going into webservice file....
please check it at the bottom of the browser you getting script error related to javascript......
because everything is right but how can i guide you to solved your problem
 
Share this answer
 
Comments
khushi mamtora 16-Mar-12 4:26am    
No, m not getting any error! Is there any alternative? I need to have a control like this. any other solution?
avinashangel 25-Jun-13 2:55am    
m not geeting any error but it is not working.........

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900