Search code examples
c#databasetabsrefreshradgrid

Refresh radgrid once changes are made to the database?


I have a page which contains a radgrid. The grid contains data retrieved from a database. It also contains an add record button that will open a new tab for the user to fill in the details for a new record. After adding the record, the user will close the opened tab.

The new record added is not displayed in the grid until the user refreshes the page. Is there any way to refresh/rebind the data in the grid when the user closes the add record tab or if the user switches back to the tab with the grid? Or is there a way to update data in the grid once any changes to the database is made even if it is not the active tab(refresh in background)?

I tried to use the function but it doesn't seem to work. Any idea why?

 $(window).focus(RefreshGrid());
        function RefreshGrid() {
            var masterTable = $find("<%= rgQualifiedLeads.ClientID %>").get_masterTableView();
            masterTable.rebind();
        }

Solution

  • I think you would need to rebind your grid so it refreshes the data on your "Close opened Tab" action/event.

    function RefreshGrid() {
        var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
        masterTable.rebind();
    }
    

    RadGrid1 is the name of your table.

    Here is the link to this function: Rebind

    Use a RadAjaxPanel or a RadAjaxManager as in this example:

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> 
        <AjaxSettings>  
            <telerik:AjaxSetting AjaxControlID="YourTable"> 
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="YourTable" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager>
    <telerik:RadGrid ID="TableUtil" ...