Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
reply C# code for autocomplate ajax bind to database
Posted
Comments
Suraj S Koneri 16-Nov-12 5:25am    
What you want? you want to bind textbox like predicting the table content?

1 solution

Hi! You can do that using Jquery UI and MVC, download Jquery UI here

Here is an example of code from this implementation.

Javascript:

XML
<script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $("#YOUR_TEXTBOX_ID").autocomplete({
                minLength: 1,
                source: function (request, response) {
                    $.ajax({
                        type: 'GET', url: 'YOUR_MVC_JSON_URL',
                        data: { 'term': request.term },
                        contentType: "application/json; charset=utf-8",
                        dataType: "json", success: function (data) {
                            response(data);
                        }
                    });
                }
            });
        });
    </script>


C# MVC
public ActionResult MyAutoComplete(string term)
        {
            string[] names =Do your Database consultation.

            return Json(names, JsonRequestBehavior.AllowGet);
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900