This is a migrated thread and some comments may be shown as answers.

[Solved] Rebind a Grid with an ajaxRequest

1 Answer 229 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sintayehu
Top achievements
Rank 1
Sintayehu asked on 13 Apr 2009, 10:42 PM
I have a grid where I delete an Item through a callback.

Reason: I am using a custom confirmation box and if the user selects YES from the radwindow,

Method : I use a javascript function to do an ajaxrequest.

Issue: The item gets deleted however the grid doesn't rebind

Code:

 <telerik:RadCodeBlock ID="RadCodeBlockConfirm" runat="server">

        <script type="text/javascript" language="javascript">
            function 'confirmDelete() {
                try {
//opening a confirm box
         var oWnd = radopen("Confirm.aspx?prompt=Do you want to delete the selected item?", "ConfirmDelete");
                }
                catch (err) {
                }
                return false;
            }
            function ConfirmResponse(tag, value) {
                try {
//User selected YES
                    if (value == "Yes") {
                        confirmHandler(value);
                    }
                }
                catch (err) {
                }
            }
            function confirmHandler(arg) {
                try {
                    if (arg) {
                            $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Delete");
                                                  }
                    }

                catch (err) {
                }
            }
        </script>

    </telerik: >


<SomeRadGrid>
<CommandItemTemplate>
<asp:LinkButton CssClass="CommandItemButton" ID="DeleteButton" OnClientClick='confirmDelete();'
                                    runat="server" Text="Delete" ></asp:LinkButton>
</CommandItemTemplate>
</SomeRadGrid>


    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager_OnAjaxRequest">
        <AjaxSettings>

//update....
          </AjaxSettings>
    </telerik:RadAjaxManager>



///////////////////////////////////////////
CODE BEHIND

/////////////////////////////////////////////

protected

void RadAjaxManager_OnAjaxRequest(object sender, AjaxRequestEventArgs e)

 

{

 

if (e.Argument.Equals("Delete"))

 

{

// Delete Item from SomeRadGrid

SomeRadGrid.Rebind(); // This looks like it is rebinding , it goes in to the need datasource and the item seems to be removed however Untill I hit refresh from the Grid It doesn't update the view

 

 

 

}

 

}

It looks like rebind doesn't update the view on 

I also tried this .......
            function RefreshGrid(ID) {

  setTimeout("RefreshGrid('<%= SomeRadGrid.ClientID %>')", 200);

                    var masterTable = $find(ID).get_masterTableView();
                    masterTable.rebind();
            }

This does rebind but I had to use a settimeout to slow it down so it doesn't rebind before the item is deleted. THis seems very unsafe and doesn't work in all cases like with more that 10 items.

Could you share a better approach.

AS a summary:

All I need is an ability to rebind after an ajaxrequest. I have to use a custom confirm box that will have to do an ajax request to delete an Item on the parent page, then i need to rebind.

Doing a radgrid.Rebind(); on the server in the onajaxrequestevent does rebind but the view does not change.

Thanx for the help!

1 Answer, 1 is accepted

Sort by
0
Accepted
Tsvetoslav
Telerik team
answered on 16 Apr 2009, 11:03 AM
Hi luay,

The grid should be one of the controls updated by the ajax request and since the RadAjaxManager is initiating the asyncronous request, you need the following ajax setting:

                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">  
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="SomeGrid" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 

I hope this helps.

Best Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Sintayehu
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or