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

Radconfirm to delete records

4 Answers 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
GlenB
Top achievements
Rank 1
GlenB asked on 19 May 2010, 04:28 AM
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:
            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">  
                        &nbsp;  
                    </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>  

(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.

4 Answers, 1 is accepted

Sort by
0
Accepted
Radoslav
Telerik team
answered on 19 May 2010, 03:37 PM
Hello GlenB,

I am sending you a simple example based on your code, which demonstrates how to achieve the desired functionality. Please check it out and let me know if it helps you.

Kind regards,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
GlenB
Top achievements
Rank 1
answered on 19 May 2010, 10:02 PM
Thanks Radoslav, but the example you attached has no code files...can you please check this.
0
Radoslav
Telerik team
answered on 20 May 2010, 02:40 PM
Hi GlenB,

I double check the zip file, it contains the runnable example. Could you please try downloading it again. Also I am sending you a screenshot of the attached example, opened with WinRAR.

All the best,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
GlenB
Top achievements
Rank 1
answered on 20 May 2010, 10:26 PM
Radoslav, thank you very much - works perfectly. Great service!

For anyone else who may need it the solution was:
Javascript:
            var btn; 
            function onToolBarClientButtonClicking(sender, args) { 
                var button = args.get_item(); 
 
                if (button.get_commandName() == "DeleteSelected") { 
                    if (document.getElementById('hdn_Hosp').value) { 
                        args.set_cancel(true); 
                        btn = args.get_item(); 
                        confirmFn('Delete ' + document.getElementById('hdn_Hosp').value + '?'); 
                    } 
                } 
            } 
 
            function confirmFn(text) { 
                var callBackFn = function (arg) { 
                    if (arg) { 
                        document.getElementById('hdn_Hosp').value = ""
                        btn.click(); 
                    } 
                } 
                radconfirm(text, callBackFn); 
            } 
 

Tags
Grid
Asked by
GlenB
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
GlenB
Top achievements
Rank 1
Share this question
or