In various situations you may want to display user-friendly message when an ajax request (triggering sorting, paging, filtering, etc. operation) finishes execution. This can be easily achieved using the ResponseScripts collection of Telerik RadGrid when the AJAX mode is enabled for the control. An alert message added to this collection will be automatically evaluated by the grid when the callback request is finalized.
The example presented below hooks the ItemCommand event of the grid in order to determine the type of command which is executed and renders an alert message in the browser. You can include additional commands in the handler to extend the presented model:
| ASPX/ASCX |
Copy Code |
|
<rad:RadGrid ID="RadGrid1" DataSourceID="AccessDataSource1" runat= "server" EnableAJAX="true" AllowSorting="true" AllowPaging="true" AllowFilteringByColumn= "true"> <PagerStyle Mode="NumericPages" /> <MasterTableView CommandItemDisplay="TopAndBottom" AllowPaging="true"> <Columns> <rad:GridEditCommandColumn UniqueName="EditCommandColumn" /> </Columns> </MasterTableView> </rad:RadGrid> <br /> <asp:AccessDataSource ID="AccessDataSource1" DataFile="~/Grid/Data/Access/Nwind.mdb" SelectCommand="SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode FROM Customers" runat="server"></asp:AccessDataSource> |
| VB.NET |
Copy Code |
|
Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles RadGrid1.ItemCommand If (CType(source, RadGrid).EnableAJAX) Then Select Case (e.CommandName) Case RadGrid.EditCommandName RadGrid1.ResponseScripts.Add( "alert('Edit operation started')") Case RadGrid.InitInsertCommandName RadGrid1.ResponseScripts.Add( "alert('Init insert operation started')") Case RadGrid.PerformInsertCommandName RadGrid1.ResponseScripts.Add( "alert('Insert operation complete')") Case RadGrid.UpdateCommandName RadGrid1.ResponseScripts.Add( "alert('Update operation complete')") Case RadGrid.PageCommandName RadGrid1.ResponseScripts.Add( "alert('Page changed')") Case RadGrid.FilterCommandName RadGrid1.ResponseScripts.Add( "alert('Filtering performed')") Case RadGrid.SortCommandName RadGrid1.ResponseScripts.Add( "alert('Column sorted')") Case RadGrid.CancelCommandName RadGrid1.ResponseScripts.Add( "alert('Edit/Insert cancelled')") Case RadGrid.RebindGridCommandName RadGrid1.ResponseScripts.Add( "alert('Grid data refreshed')") End Select Else End If End Sub |
| C# |
Copy Code |
|
protected void RadGrid1_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e) { if ((source as RadGrid).EnableAJAX) { switch (e.CommandName) { case RadGrid.EditCommandName: RadGrid1.ResponseScripts.Add( "alert('Edit operation started')"); break; case RadGrid.InitInsertCommandName: RadGrid1.ResponseScripts.Add( "alert('Init insert operation started')"); break; case RadGrid.PerformInsertCommandName: RadGrid1.ResponseScripts.Add( "alert('Insert operation complete')"); break; case RadGrid.UpdateCommandName: RadGrid1.ResponseScripts.Add( "alert('Update operation complete')"); break; case RadGrid.PageCommandName: RadGrid1.ResponseScripts.Add( "alert('Page changed')"); break; case RadGrid.FilterCommandName: RadGrid1.ResponseScripts.Add( "alert('Filtering performed')"); break; case RadGrid.SortCommandName: RadGrid1.ResponseScripts.Add( "alert('Column sorted')"); break; case RadGrid.CancelCommandName: RadGrid1.ResponseScripts.Add( "alert('Edit/Insert cancelled')"); break; case RadGrid.RebindGridCommandName: RadGrid1.ResponseScripts.Add( "alert('Grid data refreshed')"); break; } } else { // display user-friendly notification (for example with registering alert script on the page) } } |