Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
$(document).ready(function () {
    //debugger;
    $("#txtValue").autocomplete({
        source: '@Url.Action("Getbusiness")',
        minLength: 2,
        maxResults: 5
    });




Am getting all data from database table.. i need to display only 5 items in auto-complete list.. how to do that ?? kindly help me to solve this
Posted

1 solution

That won't work in jQuery because jQuery in real isn't pulling the data from your database server instead it is your server-side language which is pulling the records and then passing to that autocomplete as a result. Rather than looking for jQuery solution, make changes on your server side, change your SQL query from

SQL
SELECT * FROM...

to
SQL
SELECT TOP 5 * FROM...


This would make sure that only top 5 records are selected from your database. jQuery has nothing to do with this logic. jQuery would just send an asynchronous request and pull the response. That's it. The actual logic would be implemented there.

A personal tip would be to send a variable to server to pull data. For example, try appending a query string as, getbusiness?records=5. Use the value for records and get the number of records. Never hard-code your source code, it would make it hard to upgrade it later instead make a few cases which can be easily edited as per your recent and future needs.
 
Share this answer
 
Comments
Member 11367931 10-Aug-15 0:46am    
Thanks
Afzaal Ahmad Zeeshan 10-Aug-15 3:44am    
You can also mark this post as 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