AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 problem with autocomplete
Posted by vamshi on  10/21/2008 5:53:17 AM Category: AJAX
Add to my favorites
Email to friend
iam using autocomplete control i wriiten the following code


webservice.aspx:

public string[] GetCountryInfo(string prefixtext)
{
int count = 10;
SqlConnection con=new SqlConnection("user id=sa;password=S7eamB0at;database=master;server=.;");

string str="select * from country where countryname like @prefixtext";
SqlDataAdapter da = new SqlDataAdapter(str, con);
da.SelectCommand.Parameters.Add("@prefixtext", SqlDbType.VarChar, 50).Value = prefixtext + "%";
DataTable dt = new DataTable();
da.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["countryname"].ToString(),i);
i++;
}
return items;


}

}


default.aspx:

<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1" ServiceMethod="GetCountryInfo" ServicePath="autocomplete.asmx" MinimumPrefixLength="1">
</cc1:AutoCompleteExtender>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>



but the oupput is not coming a please help me

Post Your Reply Post New Question

 Viewer's Reply
Check WebMethod's Number of parameters
Answered By Moderator1 on 10/21/2008 8:40:10 AM
The no. of parameters in your webmethod is only one. Actually the webmethod for Autocomplete Extender MUST contain 3 parameters. And it MUST be of same name also. For your reference a sample web method is given below.

[WebMethod]
public string[] GetCountryOrStatesInfo(string prefixText, int count, string contextKey)
{
int count = 10;
string sql;
if (contextKey == "Country")
sql = "Select Country_Name from Country Where Country_Name like @prefixText";
else
sql = "Select States_Name from States Where States_Name like @prefixText";

SqlDataAdapter da = new SqlDataAdapter(sql,”Your connection String”);
da.SelectCommand.Parameters.Add("@prefixText",SqlDbType.VarChar, 50).Value = prefixText + "%";
DataTable dt = new DataTable();
da.Fill(dt);

string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr[0].ToString(), i);
i++;
}

return items;
}

Also read our article on AutoComplete Extender From Database at
http://www.aspdotnetcodes.com/AutoComplete_Textbox_Addtional_Parameters.aspx

Good luck
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
The ASP.NET 2.0 Anthology: 101 Essential Tips, Tricks & Hacks - Free 156 Page Preview
Website Magazine
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview