Friday, February 1, 2013

Jquery Autocomplete in dotnet

This is a small tutorial of how to implement jquery autocomplete text box in dot net. You can try in any plat form  using these steps.

First you need to download or add reference to these scripts and css.

<link href="" rel="stylesheet" type="text/css" />

<script src="" type="text/javascript"></script>

<script src="" type="text/javascript"></script>

The download links for the above files are

Actually we are getting the autocomplete text as comma separated string from db,

public string Autocomplete
          return "c++, java, php, coldfusion, javascript, asp, ruby";

I implemented it like a property.

And the jqery part is very simple.

$(document).ready(function () {
    var tags = '<%=Autocomplete %>'; // Property from code behind
    tags = tags.replace("'", ""); // Spliting the string with comma and putting it into array
    var tagArray = tags.split(",");
    $("#<%=txtAutocomplete.ClientID %>").autocomplete({
         source: tagArray

 Simple and nice...


Download sample Click here


No comments:

Post a Comment