About the author

Imran Imran
Like Development in DotNet.

E-mail me Send mail

Recent Articles

 
1: Roles And Membership
Category: ASP.Net
Added: 6/2/2008

 
2: ListView and DataPager in ASP.NET 3.5
Category: ASP.Net
Added: 5/15/2008

 
3: Asp.Net Cookies
Category: ASP.Net
Added: 5/8/2008

 
4: DatagridDatalistRepeater
Category: ASP.Net
Added: 5/8/2008

 
5: mySql With Asp.Net
Category: Databases
Added: 4/16/2008

 
6: MDF without LDF
Category: Databases
Added: 4/16/2008

 
7: Disable Right Click
Category: Java Script
Added: 4/16/2008

 
8: String Functions
Category: ASP.Net
Added: 3/20/2008

 
9: Water Mark
Category: HTML & DHTML
Added: 3/20/2008

 
10: Ajax With Javascript
Category: AJAX
Added: 3/10/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