implement autocomplete for multiple text boxes at a time using database [Resolved]

Posted by Rickeybglr under ASP.NET AJAX on 8/24/2012 | Points: 10 | Views : 11046 | Status : [Member] | Replies : 5
Hi,

i am able to implement autosuggest for one textbox. but i want to implement same for multiple textboxes.
wat i am doing is: i have some search parameters like Name, City, Email ID. for which i want to implenmnt autosuggest/autocomplete.
here is my script in which i have mention textbox id of name, how can i specify other text box id plzz suggest

<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$(".autosuggest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "extendedSearch.aspx/GetAutoCompleteData",
data: "{'userName':'" + document.getElementById('txtSearchUname').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});

}
</script>




Responses

Posted by: Johnbhatt on: 8/27/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
You can do this using Ajax AutocompleteExtender.

Create a PageMethod in backend and call the same in multiple Textbox.

John Bhatt
Glad to Know, Free to Share.....
http://www.johnbhatt.com

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rickeybglr on: 8/27/2012 [Member] Starter | Points: 25

Up
0
Down
thanks ..but its not working can u please luk into the below code:

<form id="form1" runat="server">

<ajax:ToolkitScriptManager ID="ScriptManager1" runat="server"/>
<div>
<asp:TextBox ID="txtSearchUname" runat="server"></asp:TextBox>
<ajax:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtSearchUname"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="1000"
ServiceMethod="GetAutoCompleteUserNames">
</ajax:AutoCompleteExtender>
</div>

</form>

code behind :

protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetAutoCompleteUserNames(string userName)
{

SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand
("SELECT username from userRegistrationTB WHERE username LIKE @txtSearchUname+'%'", con);

cmd.Parameters.AddWithValue("@txtSearchUname", userName);

SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

List<string> allNames = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
allNames.Add(dt.Rows[i][1].ToString());
}

return allNames;
}
}


Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nkkppp on: 8/27/2012 [Member] Starter | Points: 25

Up
0
Down
Dude,

I think the select query is not returning any output.....Just debug the code by placing a break point at the Select query....copy the query and run it in sql server.

Hope this will help..



Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rickeybglr on: 8/27/2012 [Member] Starter | Points: 25

Up
0
Down
Hi All,
@NKKppp query is fine i forgot to mention [System.Web.Script.Services.ScriptMethod()] [WebMethod] above method. now its working properly.
thanks everyone for posting,

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandyverma1985 on: 12/15/2012 [Member] Starter | Points: 25

Up
0
Down
if i am doing this it gives an error .


can i use this on my master page if i am doing this it gives an error ...


sandeep kumar

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response