I would like to replace args.set_cancel(!confirm('Delete all selected customers?')) as in the example located at http://demos.telerik.com/aspnet-ajax/toolbar/examples/applicationscenarios/gridcommanditem/defaultcs.aspx?product=toolbar with a radconfirm window. I have spent hours trying different methods to achieve this and have run out of ideas.
I am using a radtoolbar as a radgrid commanditem and my code is as follows:
Javascript:
ASPX:
(there is some other javascript there, but nothing to do with the delete command).
I haven't posted what I've tried as i've tried 15 different ways to replace the delete method with a radconfirm, so thought it would be better to post what I currently have (which works).
If someone can assist with how to implement a radconfirm when using a radtoolbar in a radgrid I would be very grateful.
I am using a radtoolbar as a radgrid commanditem and my code is as follows:
Javascript:
function onToolBarClientButtonClicking(sender, args) { |
var button = args.get_item(); |
if (button.get_commandName() == "DeleteSelected") { |
if (document.getElementById('hdn_Hosp').value) { |
args.set_cancel(!confirm('Delete ' + document.getElementById('hdn_Hosp').value + '?')); |
} |
} |
} |
ASPX:
<form id="form1" runat="server"> |
<asp:HiddenField ID="hdn_Hosp" runat="server" /> |
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"> |
</telerik:RadScriptManager> |
<telerik:RadFormDecorator ID="FormDecorator1" runat="server" DecoratedControls="all"> |
</telerik:RadFormDecorator> |
<telerik:RadWindowManager ID="RadWindowManager1" runat="server"> |
</telerik:RadWindowManager> |
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> |
<AjaxSettings> |
<telerik:AjaxSetting AjaxControlID="RadGrid_Hospitals"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="RadGrid_Hospitals" /> |
<telerik:AjaxUpdatedControl ControlID="hdn_Hosp" /> |
<telerik:AjaxUpdatedControl ControlID="RadToolBar_HospitalCMD" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
<telerik:AjaxSetting AjaxControlID="btnSubmit"> |
<UpdatedControls> |
<telerik:AjaxUpdatedControl ControlID="btnSubmit" /> |
</UpdatedControls> |
</telerik:AjaxSetting> |
</AjaxSettings> |
</telerik:RadAjaxManager> |
<div> |
<asp:SqlDataSource ID="ds_Hospitals" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" |
DeleteCommand="DELETE FROM [Sub_Hospitals] WHERE [HospID] = @HospID" InsertCommand="INSERT INTO [Sub_Hospitals] ([UserID], [Hospitalname]) VALUES (@UserID, @Hospitalname)" |
SelectCommand="SELECT * FROM [Sub_Hospitals] WHERE ([UserID] = @UserID) ORDER BY [Hospitalname]" |
UpdateCommand="UPDATE [Sub_Hospitals] SET [UserID] = @UserID, [Hospitalname] = @Hospitalname WHERE [HospID] = @HospID"> |
<SelectParameters> |
<asp:CookieParameter CookieName="UserID" Name="UserID" Type="Int32" /> |
</SelectParameters> |
<DeleteParameters> |
<asp:Parameter Name="HospID" Type="Int32" /> |
</DeleteParameters> |
<UpdateParameters> |
<asp:Parameter Name="UserID" Type="Int32" /> |
<asp:Parameter Name="Hospitalname" Type="String" /> |
<asp:Parameter Name="HospID" Type="Int32" /> |
</UpdateParameters> |
<InsertParameters> |
<asp:CookieParameter CookieName="UserID" Name="UserID" Type="Int32" /> |
<asp:Parameter Name="Hospitalname" Type="String" /> |
</InsertParameters> |
</asp:SqlDataSource> |
<asp:Panel ID="pnlhosplist" runat="server" CssClass="pnlmodallist"> |
<table class="tblmodallist"> |
<tr> |
<td class="tblmodallistheading_hosp"> |
|
</td> |
</tr> |
<tr> |
<td> |
<asp:Panel ID="pnlHospChoices" runat="server" ScrollBars="Vertical" CssClass="pnlModalChoices"> |
<telerik:RadGrid ID="RadGrid_Hospitals" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" |
DataSourceID="ds_Hospitals" Width="97%" AllowSorting="True" AutoGenerateColumns="false" |
GridLines="None" runat="server" AllowMultiRowSelection="False" BorderStyle="None" OnCancelCommand="DisableGridCommandButtons" |
OnSelectedIndexChanged="RadGrid_Hospitals_SelectedIndexChanged" OnEditCommand="DisableGridCommandButtons" OnInsertCommand="DisableGridCommandButtons" |
AllowMultiRowEdit="False" HorizontalAlign="NotSet" OnItemDeleted="RadGrid_Hospitals_ItemDeleted"> |
<MasterTableView Width="100%" GridLines="None" CommandItemDisplay="Top" DataSourceID="ds_Hospitals" |
ShowFooter="false" ShowHeader="false" EditMode="InPlace" HorizontalAlign="NotSet" |
DataKeyNames="HospID" AllowAutomaticInserts="True" ClientDataKeyNames="Hospitalname"> |
<NoRecordsTemplate> |
<div style="width: 200px; margin: 0 auto;"> |
<br /> |
<br /> |
<b>You currently have no favourites.</b><br /> |
<br /> |
To create a favourite click <b>Add new</b>. |
</div> |
</NoRecordsTemplate> |
<Columns> |
<telerik:GridBoundColumn DataField="HospID" HeaderText="Hospital" Visible="false"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="UserID" HeaderText="Hospital" Visible="false"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="Hospitalname" HeaderText="Hospital"> |
</telerik:GridBoundColumn> |
</Columns> |
<CommandItemTemplate> |
<telerik:RadToolBar ID="RadToolBar_HospitalCMD" OnButtonClick="RadToolBar_HospitalCMD_ButtonClick" |
runat="server" OnClientButtonClicking="onToolBarClientButtonClicking" Width="100%" AutoPostBack="true"> |
<Items> |
<telerik:RadToolBarButton Text="Save" CommandName="PerformInsert" ImageUrl="~/images/toolbar/Insert.gif" |
Visible='<%# RadGrid_Hospitals.MasterTableView.IsItemInserted %>'> |
</telerik:RadToolBarButton> |
<telerik:RadToolBarButton Text="Update" CommandName="UpdateEdited" ImageUrl="~/images/toolbar/Update.gif" |
Visible='<%# RadGrid_Hospitals.EditIndexes.Count > 0 %>'> |
</telerik:RadToolBarButton> |
<telerik:RadToolBarButton Text="Cancel editing" CommandName="CancelAll" ImageUrl="~/images/toolbar/Cancel.gif" |
Visible='<%# RadGrid_Hospitals.EditIndexes.Count > 0 OrElse RadGrid_Hospitals.MasterTableView.IsItemInserted %>'> |
</telerik:RadToolBarButton> |
<telerik:RadToolBarButton Text="Edit" CommandName="EditSelected" ImageUrl="~/images/toolbar/Edit.gif" |
Enabled='<%# RadGrid_Hospitals.EditIndexes.Count = 0 AND Not RadGrid_Hospitals.MasterTableView.IsItemInserted AND hdn_Hosp.value<>"" %>'> |
</telerik:RadToolBarButton> |
<telerik:RadToolBarButton Text="Add new" CommandName="InitInsert" ImageUrl="~/images/toolbar/AddRecord.gif" |
Visible='<%# Not RadGrid_Hospitals.MasterTableView.IsItemInserted AND RadGrid_Hospitals.EditIndexes.Count = 0 %>'> |
</telerik:RadToolBarButton> |
<telerik:RadToolBarButton Text="Delete" CommandName="DeleteSelected" ImageUrl="~/images/toolbar/Delete.gif" |
Enabled='<%# hdn_Hosp.value<>"" %>' Visible='<%# RadGrid_Hospitals.EditIndexes.Count = 0 %>'> |
</telerik:RadToolBarButton> |
</Items> |
</telerik:RadToolBar> |
</CommandItemTemplate> |
</MasterTableView> |
<ClientSettings EnablePostBackOnRowClick="true"> |
<ClientEvents OnRowClick="RowSelected" /> |
<Selecting AllowRowSelect="True" /> |
</ClientSettings> |
</telerik:RadGrid> |
</asp:Panel> |
</td> |
</tr> |
<tr> |
<td align="center"> |
<asp:Button ID="btnSubmit" runat="server" Text="Insert" OnClientClick="returnArg();" UseSubmitBehavior="false" Width="70px" /> |
</td> |
</tr> |
<tr> |
<td align="center"> |
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClientClick="closeWindow();" UseSubmitBehavior="false" Width="70px" /> |
</td> |
</tr> |
</table> |
</asp:Panel> |
</div> |
</form> |
I haven't posted what I've tried as i've tried 15 different ways to replace the delete method with a radconfirm, so thought it would be better to post what I currently have (which works).
If someone can assist with how to implement a radconfirm when using a radtoolbar in a radgrid I would be very grateful.