ajax auto complete extender not working.....

Posted by Ankitsrist under ASP.NET AJAX on 1/4/2013 | Points: 10 | Views : 8612 | Status : [Member] | Replies : 1
hello
m trying to implement ajax auto complete extender, it is giving no error nd it also not working...my webservice.asmx page is as below
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]

public class WebService : System.Web.Services.WebService
{
public WebService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}

Class1 db=new Class1 ();
public List<string>GetCountries(string prefixText)
{
db.mycon ();
SqlCommand cmd = new SqlCommand("select * from stuloginstoreproc where name like @name+'%'", db .con );
cmd.Parameters.AddWithValue("@name", prefixText);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
List<string> CountryNames = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
CountryNames.Add(dt.Rows[i][1].ToString());
}
return CountryNames;
}
}

design page default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="auto complete.aspx.cs" Inherits="auto_complete" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

</div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ServicePath= "WebService.asmx" ServiceMethod="GetCountries" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" TargetControlID="TextBox1">
</cc1:AutoCompleteExtender>
</form>
</body>
</html>


please help




Responses

Posted by: Prabu_Spark on: 1/4/2013 [Member] Starter | Points: 25

Up
0
Down
Try the below code, it is working fine for me.


Default.aspx
***********************

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>

</head>
<body>

<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ScriptManager1" runat="server"/>
<div>
<asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="txtCountry"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" DelimiterCharacters="/" CompletionInterval="100" ServiceMethod="GetName" >
</asp:AutoCompleteExtender>
</div>
</form>
</body>
</html>


Default.aspx.cs:
****************************

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> GetName(string prefixText)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
//con.ConnectionString = ConfigurationManager.ConnectionStrings["dbconnection"].ToString();



con.Open();
SqlCommand cmd = new SqlCommand("select ename from emp where ename like @Name+'%'", con);
cmd.Parameters.AddWithValue("@Name", prefixText);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
List<string> ename = new List<string>();

for (int i = 0; i < dt.Rows.Count; i++)
{
ename.Add(dt.Rows[i][0].ToString());
}

return ename;

}
}

With regards,
J.Prabu.
[Email:prbspark@gmail.com]

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

Login to post response