English 中文(简体)
Transfer Datatable from one aspx page to another C# [closed]
原标题:

Closed. This question is opinion-based. It is not currently accepting answers.


Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 9 years ago.

I have question which I hope some one can answer, what is the best way of transferring Datatable to another .aspx page so it can gathered and binded to Gridview in C#?

  • Cookies?
  • Sessions?
  • Cache?
问题回答

There is no single "best" - as it will depend on the structure of the application and the size of the lump of data you want to transfer. It will also depend on what you are doing with it at either end.

At the most basic level the answer is in Session state - cookies are inappropriate because (generalising) the lump of data you want to move is too big. Cache is there to avoid you having to reload things, but (again generalising) you shouldn t use it for things that you require to be there when you go back to look which leaves you with session.

Of course that assumes that you keep the datatable at all. The other way to do this is to just maintain the key value(s) that allow you to retrieve the datatable from store - so you load the table once for the first page, do stuff, persist the key value(s) navigate to the second page, reload the datatable from your storage and then do such updates as are required. This is notionally a better model (its a tradeoff between the overhead or serializing/deserializing the table to session vs pulling the data from the datastore and of course between datastore and application is an appropriate opportunity to cache data) and if you go down this route you can use either session or, if you want, a cookie which in turn frees you from dependency on session.

As I say, the simple, practical, answer is in Session - but you need to be aware of the overhead and of the other constraints this places upon you.

Cookies- definitely not. Session- possibly, depending on the number of users/load on server. Cache- probably not a good idea unless the same grid is view by lots of users (ie the data warrants being cached).

Can t you provide some information to the other page that would allow that page to get the data for the gridview itself- perhaps something as simple as a querystring parameter,e.g. productId=10?

Also read about cross page posting in ASP.NET.

If you perform a redirect to the other page, the Session is a good place. But if the DataTable is not too expensive to recreate I would probably send a new query to the database.

Cross page posting is one thing which you can do by exposing a property which holds your DataTable. Another option is populating the datatable again on the next page if it is not too expensive to do it again. Cache and session, I think, will be expensive. Cookies is definately not an option as it will expose all the things to client.

It depends on the contents of your datatable.

I would exclude Cookies because it forces you to transfer all the data to the client and back(guessing that if it s a DataTable it can have lots of records).

Sessions and cache will both work but take in consideration that they will be stored in memory probably for as long as the user stays with the session active.

If the query doesnt take to long to execute, i would consider just to run it again.

You could serialize it in the ViewState.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签