views:

1628

answers:

2

What best practice or strategy would you use to enable bulk insert/update in an asp.net gridview control with paging enabled?

Say for e.g. you have about 10000 records and this data gets populated when the page loads and this happens in chunks of say 100 records per webservice request.

To enable editing on these rows what approach would you follow.

Just to give an example say the object model for the fictitious scenario is given below.

List customers; // list of customers

customers = ServiceFacade.GetAllCustomers(pageSize, currentPage);

Assume the above service calls brings back 50 records based on the pageSize displaying 10 records per page.

This will be bound to the gridView as below.

gridCustomers.DataSource = customers; gridCustomers.DataBind();

Some points I would think of is outlined below and requires experts inputs...

  • Disable viewstate for gridview (as this will slow down the performance of the page).
  • Use session object to persist the change (OR what would you recommend. Is two way binding really helpful here, I don't know as I haven't tried it.)

Your ideas/suggestions are greatly appreciated. I understand I could be flamed for this, but I think the good old DataSet may be useful here (as it has all the essential information which enables tracking changes etc).

+1  A: 

Have you considered not using the ASP.Net GridView in favor of a purely client side grid control (i.e. a JQuery plugin control)? What I would suggest you consider is to perhaps use client side JSON or an XML data island as the data source, to store all the changes the user is making and then once they hit the main submit button send this payload to the server and handle all the database updates in a single batch or round trip.

The downside to this is that it is going to probably be quite a bit more work that just a ASP.Net GridView. Also you'll have to build in/incorporate an optimistic concurrency data model. Once it's all done you'll have a really fast and slick interface since most of the actions will occur client side without all the post backs. I built something like this several years back and it turned out great.

Sorry I cannot provide more, but below is a very rough skeleton of how it would work. I hope this helps.

<html>
    <head>
     <SCRIPT LANGUAGE="javascript">
     var xmlDomItems;

     function initialize()
     {
         xmlDomItems = document.all("itemsXML").XMLDocument;
         docProds.async = false;
     }

     function ModifyXMLDOM()
     {
       // just work with the xmlDomItems variable just like you would with an .Net XMLDocument Object.
     }

     function SumbitChangePayload()
     {
       // submit xmlDomItems.OuterXML to some AJAX or web service endpoint in an async manner.
     }
     </SCRIPT>
    </head>
    <body onload="initialize()">

     <XML id="itemsXML">
      <Items>
      <%
      // Server side code to render XML inner contents here...

      %>
      </Items>
     </XML>
     <form>
      <!-- build your UI here -->

      <input type="button" onclick="SumbitChangePayload()" value="Submit" />
     </form>
    </body>
</html>
James
Good alternative to try out. If you have any pointers to this please do post it.
rajesh pillai
See my last edit.
James
+3  A: 

Take a look at this article on Code Project.

UPDATE:
I found a better implementation of the same kind of control here.

Enrico Campidoglio