VB.NET+AJAX搜索建议功能的实现
DE:Visual Web Developer 2008 Express Edition
成都创新互联-专业网站定制、快速模板网站建设、高性价比开化网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式开化网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖开化地区。费用合理售后完善,十多年实体公司更值得信赖。
DB:Access 2007
到http://www.asp.net/ajax/downloads/下载AJAX Control Toolkit,将AjaxControlToolkit.dll拷贝到项目的bin目录下,在工具栏中引入。
在Web.config的
[xhtml] view plain copy
< add tagPrefix = "ajaxToolkit" namespace = "AjaxControlToolkit" assembly = "AjaxControlToolkit" />
WebService的代码:(aaa.asmx)
[vb] view plain copy
_ _ Public Function GetCompletionList( ByVal prefixText As String , ByVal count As Integer ) As String ()
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim dbname As String
dbname = Server.MapPath( "location.accdb" )
myConnection = New OleDbConnection( "Provider=Microsoft.ACE.OLEDB.12.0;DATA Source=" & dbname)
myConnection.Open()
Dim list As New List(Of String )
myCommand = New OleDbCommand( "SELECT DISTINCT(columnName) FROM tableName WHERE columnName LIKE '" + prefixText & "%" + "'" , myConnection)
Dim reader As OleDbDataReader = myCommand.ExecuteReader()
Do While reader.Read
list.Add(reader.GetString(0))
Loop
Return list.ToArray()
End Function
FORM中的代码:(aaa.aspx)
[xhtml] view plain copy
< asp:TextBox ID = "txtNo" runat = "server" autopostback = "true" Columns = "50" > asp:TextBox >
< ajaxToolkit:AutoCompleteExtender ID = "txtNo_AutoCompleteExtender" runat = "server" Enabled = "True" ServiceMethod = "GetCompletionList" ServicePath = "aaa.asmx" TargetControlID = "txtNo" MinimumPrefixLength = "1" EnableCaching = "true" >
ajaxToolkit:AutoCompleteExtender >
以上即可。
AJAX日期控件的使用也很方便,如:
[xhtml] view plain copy
< asp:TextBox ID = "txtDate" runat = "server" Columns = "24" > asp:TextBox >
< ajaxToolkit:CalendarExtender ID = "txtDate_CalendarExtender" runat = "server" Enabled = "True" TargetControlID = "txtDate" >
ajaxToolkit:CalendarExtender >
如果您觉得此篇文章对您有帮助,欢迎关注微信公众号:大禹编程,您的支持是对我最大的鼓励!共同学习,共同进步:)
当前题目:VB.NET+AJAX搜索建议功能的实现
文章分享:http://azwzsj.com/article/ijdoge.html