Reputation: 225
I have a checkboxlist in my C#/asp.net project and I'm populating it with a dataTable that gets data from a query to my database. The query returns a large amount of data and I want to restrict the number of elements that it shows initially before I filter the data. (To, say, the top 1000). How would I go about doing this?
Upvotes: 1
Views: 357
Reputation: 6270
There are two places where you can limit the number of data.
In the database (assuming you use SQL Server) you can modify the query to return the top 1000 rows.
SELECT TOP 1000 * FROM SomeTable
Or you can filter the data after it arrives using Linq.
var newData = dataTable.AsEnumerable().Take(1000);
I would prefer the first method, so you don't truck around useless data. But the second definitely works as well if you need that data elsewhere.
Upvotes: 2