使用ajax和c#在asp.net中自动完成文本框

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

您好,任何人都可以帮我解决使用c#和Ajax的自动填充文本框代码。我很困惑开发它。

Hello, Can anyone please help me out with the autocomplete textbox code, Which uses c# and Ajax. I'm very much confused of developing it.

推荐答案

嗨 你也可以使用这个jQuery jqueryui/demos/autocomplete/ [ ^ ]插件以及网络服务 Hi you can also use this jQuery jqueryui/demos/autocomplete/[^] plugin along with a web service

这是我的aspx文件 This is my aspx File <asp:ImageButton ID="frumgrp_srch_imgbtn" runat="server" ImageUrl="~/images/search.png" /> &nbsp;&nbsp;&nbsp;&nbsp;<br /> <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="frumgrp_srch_txt" EnableCaching="true" BehaviorID="AutoCompleteCities" ServiceMethod="GetCities" ServicePath="~/AutoComplete.asmx" MinimumPrefixLength="1" CompletionSetCount="5" FirstRowSelected="true"> </asp:AutoCompleteExtender>

这是我的Cs文件

This Is My Cs File

using System; using System; using System.Collections.Generic; using System.Web.Services; using System.Data.SqlClient; using System.Configuration; using System.Data; [WebService] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] public class AutoComplete : WebService { public AutoComplete() { } [WebMethod] public string[] GetCompletionList(string prefixText, int count) { if (count == 0) { count = 10; } DataTable dt = GetRecords(prefixText); List<string> items = new List<string>(count); for (int i = 0; i < dt.Rows.Count; i++) { string strName = dt.Rows[i][0].ToString(); items.Add(strName); } return items.ToArray(); } public DataTable GetRecords(string strName) { string strConn = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(strConn); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.Parameters.AddWithValue("@Name", strName); cmd.CommandText = "Select Name from Test where Name like '%'+@Name+'%'"; DataSet objDs = new DataSet(); SqlDataAdapter dAdapter = new SqlDataAdapter(); dAdapter.SelectCommand = cmd; con.Open(); dAdapter.Fill(objDs); con.Close(); return objDs.Tables[0]; } }

这是我的asmx文件 <![CDATA [<%@ WebService Language =C#CodeBehind =〜/ App_Code / AutoComplete.cs Class =AutoComplete%> 我无法执行此代码。事实上,它自己没有被调用的web服务。可以任何人帮助。你的帮助对我来说是一个很大的帮助。 急切等待解决方案 提前致谢

This is My asmx File <![CDATA[<%@ WebService Language="C#" CodeBehind="~/App_Code/AutoComplete.cs" Class="AutoComplete" %> I'm not able to execute this code. Infact the webservice it self is not getting called. Can Anyone help. Your help will be a great relief to me. Eagerly Waiting For The Solution Thanks in advance

我知道你已经有了以前所有帖子的答案, 但是这里为您提供了解Ajax自动完成控件的简便方法 视频: www.youtube/watch?v=2i50R-fHHlA [ ^ ] www.youtube/watch?v=nYac4sxChdk [ ^ ] 谢谢 --RA I Know you already got the answer from all previous posts, But here am providing you easy way to know about the Ajax Autocomplete control Videos: www.youtube/watch?v=2i50R-fHHlA[^] www.youtube/watch?v=nYac4sxChdk[^] Thanks --RA

更多推荐

使用ajax和c#在asp.net中自动完成文本框

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

发布评论

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

>www.elefans.com

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