GridButtonColumn, RadWindow and ConfirmText

2 posts, 1 answers
  1. digitall
    digitall avatar
    169 posts
    Member since:
    Jun 2006

    Posted 21 Jun 2010 Link to this post

    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?



  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 22 Jun 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top