简体   繁体   中英

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?

ps the update function I am currently 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM