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

Need dynamic ConfirmText on programmatically added column

4 Answers 220 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 01 Jun 2009, 11:23 PM
Hello,

If need to create a 'delete column' programmatically due to authorization constraints ( I need to show or hide the column based on privilege) that prompts for delete but I would rather it say 'Delete client John Smith?' rather than 'Delete this client?' i.e. I would like to personalize it for each row.  This is what I have now:

 if (((UserProfile)Session["_userProfile"]).IsAuthorized("Client - Delete"))  
        {  
            _buttonColumn = new GridButtonColumn();  
            radGridClients.MasterTableView.Columns.Add(_buttonColumn);  
            _buttonColumn.ButtonType = GridButtonColumnType.ImageButton;  
            _buttonColumn.ConfirmDialogType = GridConfirmDialogType.Classic;  
            _buttonColumn.ConfirmText = "Delete this client?";  
            _buttonColumn.HeaderText = "Delete";  
            _buttonColumn.HeaderStyle.Width = 40;  
            _buttonColumn.CommandName = "Delete";  
            _buttonColumn.ImageUrl = "./images/delete.gif";  
        } 

When using a declarative template column I could do an "Eval" to get the cuurent row on the databaind using a template column like so:

            <telerik:GridTemplateColumn   
                UniqueName="TemplateDeleteColumn" 
                HeaderText="Delete" 
                HeaderStyle-Width="60" > 
                <ItemTemplate> 
                    <asp:ImageButton ID="DeleteButton" OnClick='<%# Eval("NameLast2First", "return confirm(\"Delete all record of the Client {0} from the database?\");" ) %>'  runat="server"  ImageUrl="./images/delete.gif" CommandName="Delete"  /> 
                </ItemTemplate> 
            </telerik:GridTemplateColumn> 

How would one create a dynamic ConfirmText when creating the column programatically?

Thanks
Jonathan

4 Answers, 1 is accepted

Sort by
0
Jonathan
Top achievements
Rank 1
answered on 02 Jun 2009, 12:06 AM
OK I solved it myself.

    protected void radGridClients_ItemDataBound(object sender, GridItemEventArgs e)   
    {  
        if (e.Item is GridDataItem)  
        {  
            //Get the instance of the right type  
            GridDataItem dataBoundItem = e.Item as GridDataItem;  
 
            TableCell cell = dataBoundItem["Delete"];  
 
            ImageButton btnDelete = (ImageButton)cell.Controls[0];  
            btnDelete.Attributes.Add("onclick""return " + "confirm('Are you sure you want to delete Client: " +  
            ((Person)dataBoundItem.DataItem).FirstName + " " + ((Person)dataBoundItem.DataItem).LastName + "')");   
 
        }        
     }      
 

Cheers
0
Developer
Top achievements
Rank 1
answered on 16 Apr 2010, 03:21 PM
Thanks, but can anyone tell me how can I use the same method to show a RadConfirm instead of normal confirm?


Regards.
0
Radoslav
Telerik team
answered on 21 Apr 2010, 01:36 PM
Hello Developer,

To achieve the desired functionality you could try adding the GridButtonColumn into the RadGrid:
<telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton"
 ImageUrl="images/Delete.gif" UniqueName="DeleteColumn">
</telerik:GridButtonColumn>

On RadGrid.ItemDataBound you could attach the function which calls radconfirm, on the onclick event:
void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
   if (e.Item is GridDataItem)
   {
       GridDataItem item = e.Item as GridDataItem;
       TableCell cell = item["DeleteColumn"];
       ImageButton btnDelete = (ImageButton)cell.Controls[0];
       btnDelete.Attributes.Add("onclick", "confirmFn('Are you sure you want to delete Client','" + item["ID"].Text + "'); return false;");
   }
}

When the radconfirm is shown and the user clicks OK button , you could fire a custom command:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
   <script type="text/javascript">
        function confirmFn(text, itemIndex) {
           var callBackFn = function(arg) {
                 if (arg) {
                     var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
                      masterTable.fireCommand("MyCustomCommand",itemIndex);
                 }
             }
             radconfirm(text, callBackFn);
         }
    </script>
</telerik:RadCodeBlock>

Then on  RadGrid.ItemCommand you could perform deleting:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
   if (e.CommandName == "MyCustomCommand")
   {
    string ID = e.CommandArgument;
        // Delete item
   }
}

Also note that you need to have the RadWindowManager control placed on the page.

I hope this helps.

Greetings,
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
Michael
Top achievements
Rank 1
answered on 08 Sep 2011, 04:08 PM
I hate to resurrect this topic, but I would like to request that you guys add properties for "ConfirmTextFormatString" and "ConfirmTextFields", similar to what you have for the GridHyperlinkColumn.  I never understood why that wasn't done, when so many people keep asking how to display dynamic confirmation text messages.  I know custom confirm text can be done without too much hassle through a few different ways, but it would be super simple with those suggested properties.  If there is some technical reason for not doing adding that, I would be interested in the details.  Thanks!!

EDIT:  I just noticed that the latest version does have this (my company is not yet on the latest).  I should have verified in the latest version before posting.  Thank you for adding this capability, and I look forward to using it!

To anyone else looking for it, go here:  http://www.telerik.com/help/aspnet-ajax/p_telerik_web_ui_gridbuttoncolumn_confirmtextformatstring.html
Tags
Grid
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Jonathan
Top achievements
Rank 1
Developer
Top achievements
Rank 1
Radoslav
Telerik team
Michael
Top achievements
Rank 1
Share this question
or