Radgrid disappearing

1 Answer 59 Views
Miscellaneous
Rakhee
Top achievements
Rank 1
Iron
Iron
Iron
Rakhee asked on 10 May 2023, 08:54 AM | edited on 10 May 2023, 08:55 AM

I am using a radgrid which has edit form for each row. When I click on the EDIT, needdatasource event is triggered and databinding, which I dont want it to do because the query for the grid takes a fews seconds to run. I set on the needdatasource event so that the code doesn't run if the EDIT link is clicked on. But this makes the radgrid disappear. I have tried making the grid visible again and enable but doesnt show the grid. Code snippet below.

 protected void rg_OrderSummary_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
                if (refreshGrid)
                {

                    (sender as RadGrid).DataSource = LoadResults();
                }
                else
                {
                    rg_OrderSummary.Visible= true;
                    updGrid.Update();
                }
            }

}

How can I get it the grid to show without having to run databind again through need datasource event please?

 

                             

1 Answer, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 15 May 2023, 07:54 AM

Hi Rakhee,

Limiting the Grid from binding to data will also prevent it from rendering. The NeedDataSource event must contain data every time the Grid calls it. The following article shows how often the Grid calls the NeedDataSource event: Commands that invoke Rebind Implicitly.

Since the issue is about the time-consuming SQL Query, there is an approach you can take to improve that. You can query the database once, store the results in the server memory (e.g. Session, Cookie), and re-use this data whenever needed instead of making round-trips to the database. The following article shows an example of that approach: Improve performance by reducing the number of slow queries to the database

Only after Inserting/Updating/Deleting to/from the database, you you should refresh the data in the memory by making a SQL Query to the server again and fetching the fresh information.

Also note, that the DataBind() method must not be called anywhere as this works against the Grid's data binding mechanism. If you need to refresh the Grid at any point, you can call the Rebind() method. That will cause the Grid to call the NeedDataSource event again, see Programmatic Data Binding Using the NeedDataSource Event

Regards,
Attila Antal
Progress Telerik

Heads up! Telerik UI for ASP.NET AJAX versions for .NET 3.5 and 4.0 are retired. Progress will continue shipping assemblies compatible with .NET 4.5 and later. See whether this affects your apps in this article.
Rakhee
Top achievements
Rank 1
Iron
Iron
Iron
commented on 16 May 2023, 09:11 AM | edited

Thank you. Does saving the results in server memory only work for RadAjaxManager? I am using radGrid

 

Attila Antal
Telerik team
commented on 16 May 2023, 09:42 AM

The article I shared earlier(Improve performance by reducing the number of slow queries to the database) uses RadAjaxManager only to illustrate the Loading time. If you inspect the code, you can see that RadGrid is binding to the data stored in the session.

 


Tags
Miscellaneous
Asked by
Rakhee
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Attila Antal
Telerik team
Share this question
or