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

GridButtonColumn, RadWindow and ConfirmText

1 Answer 339 Views
Grid
This is a migrated thread and some comments may be shown as answers.
digitall
Top achievements
Rank 1
digitall asked on 22 Jun 2010, 01:40 AM
I am databinding a RadGrid using the NeedDataSource event and my grid has a column configured as such:

<telerik:GridButtonColumn ButtonType="PushButton" CommandName="Delete" Text="Delete" ItemStyle-Width="20px" ConfirmDialogType="RadWindow" ConfirmText="Are you sure you wish to remove this item?<br /><br /><strong>This action is not reversible.</strong>" ConfirmTitle="Confirm Removal" />

There is a RadWindow on the page so the confirmation dialog looks better than the default one. The issue I have is wanting to set the ConfirmText on ItemDataBound (or a similar method) so I can do something like "Are you sure you wish to remove this item which will also remove 35 child items?" where 35 is a count done on the DataItem being used. I've tried searching the forums here and also reading through the API and, while plenty of things give me TableCell access or access to the button being generated, I see nowhere that I can modify this text on a row-by-row basis.

Any suggestions?



1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 22 Jun 2010, 12:16 PM
Hello,

You can achieve this fuctionality by attaching OnCommand client events to the grid. Then cancel the event and explicitly call the delete using fireCommand() method based on the RadConfirm result. You can frame the radconfirm message according to the row value when calling the confirm. Sample code is given below for your reference.

ASPX:
<ClientSettings> 
    <ClientEvents OnCommand="OnCommand" /> 
</ClientSettings> 

Java Script:
<script type="text/javascript"
    var itemIndex; 
    var i = 0; 
    function OnCommand(sender, eventArgs)  
     { 
         if (eventArgs.get_commandName() == "Delete" && i == 0)  
           { 
            var grid = sender; 
            var MasterTable = grid.get_masterTableView(); 
            itemIndex = eventArgs.get_commandArgument(); 
            var row = MasterTable.get_dataItems()[itemIndex]; 
            var cellValue = row.get_cell("CategoryID").innerHTML
            radconfirm("Are you sure you wish to remove this item which will also remove" + cellValue + "child items?", confirmCallBackFn); 
            eventArgs.set_cancel(true); 
           } 
    } 
    function confirmCallBackFn(arg) { 
        if (arg)  
          { 
              if (!i) 
               { 
                i = 1; 
                var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView(); 
                masterTable.fireCommand("Delete", itemIndex); 
               } 
          } 
    } 
</script> 


Thanks,
Princy.
Tags
Grid
Asked by
digitall
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or