views:

1362

answers:

3

Is there a way to avoid postbacks with gridview every time a row is added to it?

In other words, can I store the DataTable on the client and pass it on to the server control when I am done to save, rather than do postbacks every time the row is added?

I searched and searched....all I could find was web services, JSON, and I have a feeling it's redundant here...it's a simple task I am sure everyone had to do at some point.

Can anyone shed some light on this?

A: 

I don't konw of anything that lets you do that with the gridview out of the box, except the UpdatePanel, but that doesn't really count. If you want to implement I a full AJAX grid I would look into using the ListView Control, which will give you much more control over the resulting html.

Heres a great article from MSDN Magazine http://msdn.microsoft.com/en-us/magazine/cc337898.aspx

bendewey
+2  A: 

There is no avoiding postbacks if you're dealing with a standard ASP.NET GridView that utilizes ViewState.

You can however, disable ViewState and manually (programmatically) render the control on every page load. This will let you control every aspect of row creation/removal/updates, but you'll have to do it all manually. And yes, you'll utilize AJAX to read from or update on the server.

Kon
A: 

Thanks, guys. I think next time the performance is an issue I will look into it. Otherwise I will stick with the gridview out of the package.

gnomixa
Righto.. if you want to give it an AJAX-ey kind of look and feel, throw an UpdatePanel around your GridView. The end-user perception will be that only the grid is refreshing, not the whole page.
Kon
If performance is an issue next time, stay away from update panels and gridviews altogether.
Mike Robinson
@Mike, I think that's been covered.
Kon