0

I have an asp.net web app. The main thread starts a child thread which populates (at a high rate) a DataTable with random generated data. I keep the DataTable in the Application object.

I want to bind a gridview to this DataTable each time a new row is added to the table.

How can i accomplish this? How can the main Thread call DataBind on my GridView every time DataTable gets updated?

Thank you.

2 Answers2

0

Binding a grid in the view to a dataset in the application requires a postback. If you are programmatically adding rows at a high rate you will either need to do a ton of postbacks for each insert (which will get messy) or be satisfied with a normal frequency of postbacks.

If you want to put them into the grid quickly without postbacks you'll need to add them to the view with a script then postback to the application on a schedule.

Matthew
  • 10,244
  • 5
  • 49
  • 104
0

No it cannot. Your best bet is to put this either in an update panel with a timer that checks for updates, or an ajax call to check if the rowcount has changed, if so then update your update panel. There are other 'less easy' options like push notifications (ie comet framework)

What are you trying to accomplish that must have the real time update? Most web apps use a polling technique to check the server.

Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
  • I'm already inside an update panel, with a timer that triggers the gridview data binding every millisecond. But the data rate can vary over time and is seems tedious to perform 1000 databindings / sec in a period when the data rate is 100 rows / sec. I would need to trigger the databinding process in an event-based manner, rather than time based. I'm interested in how to place that Ajax call that checks if my table was updated. Wouldn't this also imply a time-based approach? Would appreciate any links for research. Thank you. – laailalalaa Jul 12 '11 at 16:36
  • why would you bind 1000 a sec? your data cant even render back that fast so it will never ever ever matter that it is happpening that fast. What are you trying to accomplish to have it bind so fast? – Adam Tuliper Jul 12 '11 at 20:38
  • yes - it would imply a time based approach - since it is polling. the other option is some push notification but implementation seems difficult - see: http://stackoverflow.com/questions/5427681/how-do-modern-implementations-of-comet-reverse-ajax-work-any-stable-c-wcf-or-as for a polling approach you check say, once every two seconds for updated data based on the last say timestamp. You will not process this data with large sets of data fast by polling it 1000 times a second. no one will do that so must ask again what are you trying to accomplish here? – Adam Tuliper Jul 12 '11 at 20:44
  • i want to maintain in the griview the last 20 items (data rows) that came from my datasource. this means every time a data item arrives at the application, the DataTable will eliminate the oldest datarow it holds and add the new data item. hence a databind must be performed for every new data item. so checking once every two seconds for an updated DataTable is not what i need. i will check that link on push notification. thanks for your suggestion – laailalalaa Jul 13 '11 at 07:51
  • an interesting suggestion here: http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/6bd56bf7-35a5-4c9c-bdc2-19e37e1605f9 . i'm wrkin on it right now, will post my results. – laailalalaa Jul 13 '11 at 08:03
  • I dont see where the benefit is there - you still have to do a high number of binds which are potentially a waste. simply check for updates via a small call to the server by passing in for ex. the last record id number - and if there are updates then ask for them. ideally if you have to do this a lot you want this very light weight and a service call using JSON is about the lightest weight response you can get for network traffic. – Adam Tuliper Jul 18 '11 at 15:36