About the author

Imran Imran
Like Development in DotNet.

E-mail me Send mail
Search Entire Web

Recent Articles

 
1: Master Pages
Category: ASP.Net
Added: 1/31/2008

 
2: Caching with ASP.NET
Category: ASP.Net
Added: 1/31/2008

 
3: Free Microsoft Press E-Book Offer!
Category: ASP.Net
Added: 1/30/2008

 
4: Timer Control in Asp.Net
Category: ASP.Net
Added: 1/29/2008

 
5: Checkbox selection with ajax
Category: ASP.Net
Added: 1/29/2008

 
6: UrlRewriter with asp.net
Category: ASP.Net
Added: 1/19/2008

 
7: Auto complete textbox with Ajax
Category: ASP.Net
Added: 1/15/2008

 
8: Upload file with Asp.Net
Category: ASP.Net
Added: 1/15/2008

 
9: User Rating Technique
Category: ASP.Net
Added: 1/8/2008

 
10: Encryption And Decryption Library
Category: ASP.Net
Added: 1/5/2008

Auto complete textbox with Ajax

by Imran 15/January/2008

Some days before i was a problem i want to use autocomplete textbox with ajax. I found it from following link below

Ajax.NET comes without any web control, it is designed only for data exchange with the web server.

Here you will see how easy it is to implement a AutoComplete feature.

http://munich.schwarz-interactive.de/autocomplete.aspx

then i integrate it with in my system with some changes

Default.aspx

<p>

Customer:

<input type="text" id="searchCustomerID" /></p>

<script type="text/javascript" src="scripts/autocomplete.js"></script>

<script type="text/javascript">

function init() {

var x = new MS.Web.AutoCompleteDataTable("searchCustomerID", 10);

x.getDisplay = function(item) {

return (item != null ? item.CustomerName : "");

}

x.getValue = function(item) {

// return item.CustomerID;

return (item != null ? item.CustomerName.toString().trimRight() : "");

}

x.getData = function() {AutoComplete.Search(this.ele.value, this.count, this.callback.bind(this));

}

}

setTimeout(init, 1);

</script>

Default.aspx.vb

Imports System.Data

Imports System.Data.SqlClient

Partial Class _Default

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

AjaxPro.Utility.RegisterTypeForAjax(GetType(AutoCompleteWebForm))

End Sub

End Class

<AjaxPro.AjaxNamespace("AutoComplete")> _

Partial Public Class AutoCompleteWebFormInherits System.Web.UI.Page

<AjaxPro.AjaxMethod()> _

Public Function SimpleSearch(ByVal search As String) As String()

Return New String() {"AAA", "BBB", "CCC", search}

End Function

<AjaxPro.AjaxMethod()> _

Public Function Search(ByVal searchstr As String, ByVal count As Integer) As DataTable

Dim dt As New DataTable()dt.Columns.Add(

"CustomerID", GetType(Integer)) dt.Columns.Add("CustomerName", GetType(String))

Try

Try

Dim row As DataRow

row = dt.NewRow()

row("CustomerID") = "1"

row("CustomerName") = "2"

dt.Rows.Add(row)

row = dt.NewRow()

row("CustomerID") = "1"

row("CustomerName") = "3"

dt.Rows.Add(row)

Finally

End Try

Catch ex As Exception Throw ex

End Try

Return dt End Function

End Class

 





Powered by DotNetClassic.com