使用ajax的asp.net 3.5中的自动完成文本框

编程入门 行业动态 更新时间:2024-10-18 06:05:27
本文介绍了使用ajax的asp 3.5中的自动完成文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在我的数据库中使用ajax在asp 3.5中实现自动完成文本框.我有一个使用ajaxtoolkit.dll的示例代码,但它不起作用,我不知道为什么会不起作用怎么办,我想我在代码中遗漏了一些东西,但是我找不到它.由于我是ajax的新手,所以请帮助我 我的代码如下: Default.aspx

Hi, i want to implement the auto complete text box in asp 3.5 using ajax with my database.I have a sample code which is using ajaxtoolkit.dll but it is not working ,i dont know what happen why it is not working ,i thought that i have missing some thing in the code but what ican not caught it out.As i am new to ajax .So plz help me my code as follows: Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" tagprefix="ajaxToolkit"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "www.w3/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="www.w3/1999/xhtml"> <head id="Head1" runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> <Services> <asp:ServiceReference Path="AutoCompleteTest.asmx" /> </Services> </asp:ScriptManager> <div> <asp:TextBox ID="txtCountry" runat="server"></asp:TextBox> <ajaxToolkit:AutoCompleteExtender runat="server" ID="autoComplete1" TargetControlID="txtCountry" ServicePath="AutoCompleteTest.asmx" ServiceMethod="GetCountriesList" MinimumPrefixLength="1" EnableCaching="true" /> </div> </form> </body> </html>

[Web服务AutoCompleteTest.asmx] AutoCompleteTest.cs

[web service AutoCompleteTest.asmx] AutoCompleteTest.cs

using System; using System.Collections.Generic; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Data; using System.Data.SqlClient; using System.Configuration; /// <summary> /// Summary description for AutoCompleteTest /// </summary> [WebService(Namespace = "tempuri/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class AutoCompleteTest : System.Web.Services.WebService { public AutoCompleteTest () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public string[] GetCountriesList(string prefixText) { DataSet dtst = new DataSet(); SqlConnection sqlCon = new SqlConnection(ConfigurationManager.AppSettings["AppConnString"]); string strSql = "SELECT Name FROM Colleges WHERE Name LIKE '" + prefixText + "%' "; SqlCommand sqlComd = new SqlCommand(strSql, sqlCon); sqlCon.Open(); SqlDataAdapter sqlAdpt = new SqlDataAdapter(); sqlAdpt.SelectCommand = sqlComd; sqlAdpt.Fill(dtst); string[] cntName = new string[dtst.Tables[0].Rows.Count]; int i = 0; try { foreach (DataRow rdr in dtst.Tables[0].Rows) { cntName.SetValue(rdr["Name"].ToString(), i); i++; } } catch { } finally { sqlCon.Close(); } return cntName; } }

我使用了bin文件夹中的AjaxToolkit .dll.我提供的代码plz告诉我此

I have use AjaxToolkit .dll which is in bin folder.I have provided the code plz tell me what is wrong in this

推荐答案

// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class AutoCompleteTest : System.Web.Services.WebService

出了什么问题 如果您如上所述取消web服务中的行注释,是否行得通?

Does it work if you uncomment the line in the webservice as above?

您应该使用字符串prefixtext和int count作为服务方法的参数,因为您使用的是ajax控件工具包. /> //Count用于指定显示的建议数. public string [] GetCountriesList(string prefixText,int count) You should use string prefixtext and int count as the parameters of the service method because you are using ajax control toolkit. //Count is used to specify the number of suggestions shown. public string[] GetCountriesList(string prefixText, int count)

更多推荐

使用ajax的asp.net 3.5中的自动完成文本框

本文发布于:2023-11-24 22:55:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627215.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   自动完成   asp   ajax   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!