使用Asp.net使用Ajax 2.1.3进行自动建议/自动完成 [英] Autosuggest / Autocomplete with Ajax v. 2.1.3 with asp.net

查看:102
本文介绍了使用Asp.net使用Ajax 2.1.3进行自动建议/自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



请任何人告诉我如何实施

Hi,

Please can anyone tell me how to implement

Autosuggest / Autocomplete with Ajax v. 2.1.3


使用带有示例代码的asp.net或带有jquery和asp.net的任何类似示例.
我不想使用任何DLL.

参考网址:
http://www.brandspankingnew.net/specials/ajax_autosuggest/ajax_autosuggest_autocomplete.html [ ^ ]


with asp.net with sample code or any similar sample with jquery and asp.net.
I dont want to use any DLL.

ref. url:
http://www.brandspankingnew.net/specials/ajax_autosuggest/ajax_autosuggest_autocomplete.html[^]

thanks.

推荐答案

自动完成扩展程序 [^ ]

http://www.davidhayden.com/blog/dave/archive/2007/10/22/ASPNETAJAXAutoCompleteExampleUsingAutoCompleteExtenderControl.aspx [ ^ ]
autocomplete extender[^]

http://www.davidhayden.com/blog/dave/archive/2007/10/22/ASPNETAJAXAutoCompleteExampleUsingAutoCompleteExtenderControl.aspx[^]


选中此
ASP.NET中的Ajax自动填充 [
check this
Ajax AutoComplete in ASP.NET[^]


通过AutoCompleteExtender控件,您可以帮助最终用户找到可能的结果
寻找他们何时必须在文本框中输入搜索字词.像Google建议产品一样
开始在文本框中输入字符后,您将获得来自
的结果 与您到目前为止输入的内容相匹配的数据存储.
要为自己建立类似的东西,请创建一个仅包含ScriptManager控件的新页面,
一个AutoCompleteExtender控件和一个TextBox控件.页面的ASP.NET部分应该
出现在:
The AutoCompleteExtender control provides you the ability to help the end user find what they might
be looking for when they have to type in search terms within a text box. Like the product Google Suggest
once you start typing characters in the text box, you will get results from a
datastore that matches what you have typed so far.
To establish something similar for yourself, create a new page that contains only a ScriptManager control,
an AutoCompleteExtender control, and a TextBox control. The ASP.NET portion of the page should
appear as presented in :
<br />
<br />

lt;%@页面语言="C#" AutoEventWireup ="true" CodeFile ="AutoComplete.aspx.cs"
Inherits ="AutoComplete"%>
<%@注册Assembly ="AjaxControlToolkit"命名空间="AjaxControlToolkit"
TagPrefix ="cc1"%>

lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="AutoComplete.aspx.cs"
Inherits="AutoComplete" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit"
TagPrefix="cc1" %>

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

TargetControlID="TextBox1" ServiceMethod="GetCompletionList"

UseContextKey="True">
</cc1:AutoCompleteExtender>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>




同样,与其他ASP.NET AJAX控件一样,您可以使用TargetControlID
扩展TextBox控件. 财产.首次将这些控件添加到页面时,将没有ServiceMethod
在AutoCompleteExtender控件中定义的属性.使用Visual Studio 2008,您可以将
服务方法的框架,并将扩展程序控件与此方法从设计图面联系在一起.
展开TextBox控件的智能标记后,从
中选择添加自动完成页面方法"选项 提供的菜单.
此操作将在页面的代码隐藏中创建一个服务方法.




Again, like the other ASP.NET AJAX controls, you extend the TextBox control using the TargetControlID
property. When you first add these controls to the page, you will not have the ServiceMethod
property defined in the AutoCompleteExtender control. Using Visual Studio 2008, you can make the
framework for a service method and tie the extender control to this method all from the design surface.
After expanding the TextBox control’s smart tag, select the Add AutoComplete page method option from
the provided menu.
This action creates a service method in the code-behind for your page.

<pre lang="c#"><br />
using System.Collections.Generic;<br />
using System.Data;<br />
using System.Data.SqlClient;<br />
public partial class AutoComplete : System.Web.UI.Page<br />
{<br />
[System.Web.Services.WebMethodAttribute(),<br />
System.Web.Script.Services.ScriptMethodAttribute()]<br />
public static string[] GetCompletionList(string prefixText, int count,<br />
string contextKey)<br />
{<br />
SqlConnection conn;<br />
SqlCommand cmd;<br />
string cmdString =<br />
"Select CompanyName from Customers WHERE CompanyName LIKE ’" +<br />
prefixText + "%’";<br />
conn = new<br />
SqlConnection(@"Data Source=.\SQLEXPRESS;<br />
AttachDbFilename=|DataDirectory|\NORTHWND.MDF;<br />
Integrated Security=True;User Instance=True");<br />
// Put this string on one line in your code<br />
cmd = new SqlCommand(cmdString, conn);<br />
conn.Open();<br />
SqlDataReader myReader;<br />
<pre lang="xml">List&lt;string&gt; returnData = new List&lt;string&gt;();<br />
myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);<br />
while (myReader.Read())<br />
{<br />
returnData.Add(myReader[&quot;CompanyName&quot;].ToString());<br />
}<br />
return returnData.ToArray();<br />
}<br />
}<br />
<br />
</pre>


这篇关于使用Asp.net使用Ajax 2.1.3进行自动建议/自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆