开发者

Transfer Datatable from one aspx page to another C# [closed]

开发者 https://www.devze.com 2022-12-13 13:32 出处:网络
Closed. This question is opinion-based. It is not currently accepting answers. 开发者_JAVA百科 Want to improve this question? Update the question so it can be answered with facts and citati
Closed. This question is opinion-based. It is not currently accepting answers. 开发者_JAVA百科

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.

Improve this question

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.


session will be the best opition.

0

精彩评论

暂无评论...
验证码 换一张
取 消