programmatically refreshing a datagrid in asp.net
I have an asp.net webpage that does a bunch of (slow, hence the problem) calculations and dumps them all into a datagrid in a webpage. I would like to be able to have the page show partial results.
I have figured out how to re-update the grid every time a row is done, but the page still doesn't display the results until all the calculations are complete. Does anyone know a call from asp.net that can tell the page to refresh itself?
p.s. the update function I am currentl开发者_开发问答y using is as follows:
private void updateDisplay(DataTable outputTable)
{
if (outputTable.Rows.Count > 0)
{
PlaceHolder1.Controls.Clear();
PlaceHolder1.Controls.Add(new LiteralControl("<br>"));
GridView myView = new GridView();
myView.DataSource = outputTable;
myView.DataBind();
myView.Visible = true;
PlaceHolder1.Controls.Add(myView);
}
}
You could always use something like the Ajax Timer along with some efficient paging (only pulling a small amount of data instead of everything).
This way you do a short select statement for say 10 records on an interval of every 3 seconds, and you do it outside of the process thread.
If you'd rather keep it the way you have it with updating the grid every time a row is added, then that's fine too, just make sure you start your big heavy, lifting process in a separate BackgroundWorker. I would also still implement the more efficient paging in order to keep your select statements small and streamlined.
精彩评论