Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I am using MVC dropdownlistfor to bind my list. I have over 1,00,000+ data and it freezes the page.

How to handle such huge amount of data? So, page not gets hand and unresponsive.

if there is better way, then please guide.

Thanks.

What I have tried:

I have tried with jquery scroll event and AJAX call to load data but it is not accepting and I read somewhere scroll event will not work.
Posted
Updated 7-Dec-17 9:52am
Comments
F-ES Sitecore 7-Dec-17 9:03am    
Replace the dropdown with an autocomplete textbox instead. No user can sensibly use that amount of data in a single control anyway, they have to at least have some idea of the item they need to select.

You simply do NOT put that much data into a control, EVER.

Using a dropdown to show a hundred thousand records is a really bad idea. That's not the control for the job. The only way to show that much data is paging, showing only the number of records that will fit in the display. This is something a dropdown is not suited for.

If you're going to put data into a control, you have to find some way of filtering the data down to something manageable. There is no way on earth a user is going to scroll through 10,000+ records in a control.
 
Share this answer
 
Comments
kkakadiya 7-Dec-17 8:56am    
then, Please suggest alternative.
Dave Kreskowiak 7-Dec-17 8:58am    
I already did. This requires YOU to completely redesign your user interface for the data you're displaying. Nobody in a forum can do that for you because we don't know your application, the situation you're displaying/editing data in, the data available for use, what it's requirements are, what the business rules are for this operation, ... NOTHING. Only you have that and only you can design your interface around that stuff.
kkakadiya 7-Dec-17 9:03am    
correct but there must some generic code for that you develop. I'll handle UI changes from my side.
Dave Kreskowiak 7-Dec-17 10:01am    
No, there isn't. It depends on what you're doing in the UI, what database you're using, how you're querying that database, any business and data layers you've got written, ... There is a generic IDEA, but YOU have to write the code to implement it.

There is never any such thing as "there is only one way to do this" when writing code.
As stated in the solution above, paging / filtering is your best option.
For filtering, allow parameters that can be passed and filter the data based on that. Look into LINQ Where / FIND for this. OData may be another good choice.

You could also allow parameters for paging. Using LINQ to returned "pages" of data. Based on the amount of data you are looking at, you may want to use both of these options. Make sure that whatever choice you make, you do it as close to the data as possible. You always want to focus on returning just the data you have to.

Sample LINQ paging:

int pageSize = 5;

var accountsByPage = (from a in svcContext.AccountSet
                      select new Account
                      {
                       Name = a.Name,
                      });
System.Console.WriteLine("Skip 10 accounts, then Take 5 accounts");
System.Console.WriteLine("======================================");
foreach (var a in accountsByPage.Skip(2 * pageSize).Take(pageSize))
{
 System.Console.WriteLine(a.Name);
}


This example is from MSDN: Page large result sets with LINQ[^]
 
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