There is a simple ASP application on which you need to display a very large table. On the form is a grid view:

<asp:GridView ID="VTable" runat="server" Width="774px" style="margin-left: 0px"/> 

Rather trivially, it specifies the source of the data:

  private void UploadTable(string command) { DataTable TABLE = DBWorker.ReturnTable(command)); VTable.DataSource = TABLE; VTable.DataBind(); } 

However, at the time of binding the DataBind (), a System.OutOfMemoryException . I read that the exception is caused by the fact that more than 400,000 lines cannot be written to the grid view. However, there are over a million of them in the table, what to do about it?

  • Why display such a number of lines? Who and what in this table will look? Isn't it easier to make a conclusion only on what the user needs by defining a filter for outputting data - SergeyE

1 answer 1

I think not one self-respecting user and programmer will not display more than a million lines on one page. This is not convenient and consumes a decent amount of resources (especially for the server).

For such purposes, we break into pages, say 50 lines on one page, and at the very bottom, Страница 1.2.3... 90 is displayed below the table.

Do it:

  • Break your data in parts, say by request take 50 elements, starting with the n-th.
  • Calculate how many pages you have.
  • Make the simplest get request, where the necessary page will be indicated (site.ru/data?page=10)
  • Print all pages in one line below the table (as I showed above).

Indeed, in this case, you will not take a million records and display them, but in small batches and only on demand. This is much more convenient, both for you and for the user. I'm not talking about the load on the server when getting "more than a million lines."

  • Can you give a simple example? asp 2 day I study - Sergey
  • Does this example for web forms work or only for MVC? - Sergey
  • @ Sergey, I gave you one of the possible options. You can write it yourself, without using third-party libraries. Just reload the control, so that it would receive get with the int query the pages variable and determine what data to output by it, add .skip(x).take(y) in your query, where x is the element to take and y is the number of the elements . That is, let's say you have pages = 1, take it from the first element of the collection and up to our limiter (50 say). Further pages = 2, we take from 50 elements and up to 100. And so on. - EvgeniyZ