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

ConfirmText with item data

6 Answers 263 Views
Grid
This is a migrated thread and some comments may be shown as answers.
miksh
Top achievements
Rank 1
Iron
miksh asked on 25 Mar 2014, 02:59 PM
Is it possible to add the current record data into ConfirmText message? The code below does not work. I know that it can be done in the code behind but I look for simpler solution. 
<telerik:GridButtonColumn UniqueName="DeleteColumn"
    ButtonType="ImageButton"
    CommandName="Delete"
    ConfirmText='Are you sure you want to delete this record with id: <%# Eval("ID")%> ?'
    ConfirmTitle="Delete Record"
    ConfirmDialogType="RadWindow"
    Text="Delete" >
    <ItemStyle HorizontalAlign="Center" Width="20px" />
</telerik:GridButtonColumn>

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Mar 2014, 09:05 AM
Hi Miksh,

I'm afraid its not possible from the ASPX side since Telerik.Web.UI.GridButtonColumn does not have a DataBinding event. You can achieve it from code behind as follows:

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
  {
    ImageButton btn = (e.Item as GridDataItem)["DeleteColumn"].Controls[0] as ImageButton;
    string id= (e.Item as GridDataItem)["ID"].Text;
    btn.OnClientClick = String.Format("if(!confirm('Are you sure you want to delete this record with id: {0}?'))return false;", id);
  }
}

Thanks,
Princy



0
miksh
Top achievements
Rank 1
Iron
answered on 26 Mar 2014, 12:42 PM
Thanks Princy,

We tried to use the code below. The weird thing as that the message is always applied to the next row, i.e. if you bind data with IDs: 1,2,3,4 etc, the message will be

ID       Delete Message 
1         ... with ID:
2         ... with ID:1
3         ... with ID:3

Is it a bug? We use Q1 2014 release.


protected void g_ItemDataBound(object sender, GridItemEventArgs e)
{
   if (e.Item is GridDataItem)
   {
       GridDataItem dataItem = e.Item as GridDataItem;
       if (dataItem != null)
          {
               GridColumn deleteColumn = e.Item.OwnerTableView.Columns.FindByUniqueNameSafe("DeleteColumn");
               if (deleteColumn != null)
               {
                    ((GridButtonColumn)deleteColumn).ConfirmText = string.Format("Are you sure you want to delete the record with ID: {0}?", dataItem["ID"].Text);
                }
           }
     }
}
0
miksh
Top achievements
Rank 1
Iron
answered on 26 Mar 2014, 01:07 PM
Correction: it should be

ID       Delete Message 
1         ... with ID:
2         ... with ID:1
3         ... with ID:2
etc
0
Princy
Top achievements
Rank 2
answered on 27 Mar 2014, 04:06 AM
Hi Miksh,,

The proper means to invoke a confirm dialog and set its text on a per-row basis (obtaining cell text value from the same row) is by setting onclick attribute for the button inside the GridDataItem as shown in my previous post. Please take a look at this article on Adding a Delete Confirmation.

Thanks,
Princy
0
miksh
Top achievements
Rank 1
Iron
answered on 27 Mar 2014, 01:20 PM
If the proper way doing it is onclick then why should I purchase the sophisticated set of well-integrated controls???
Btw, the documentation says that
In this case you need to implement a different approach (without setting the ConfirmText property for the delete column),...

My point is:
  1. radGrid delete functionality provides seamless integration with radWindow.
  2. It simplifies the process with ConfirmText, ConfirmTitle properties
  3. If needed these properties could be easily changed in the code-behind
  4. My code snippet shows that it works
  5. But there seen to be a bug as the updated messages is applied to the next row.
0
Eyup
Telerik team
answered on 31 Mar 2014, 09:21 AM
Hello Michael,

You can use ConfirmTextFields to achieve the requested functionality. I believe we discussed this requirement with your colleague in ticket with ID:803446. In any case, I'm attaching the sample project to this post, too.

Hope this helps.

Regards,
Eyup
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
Tags
Grid
Asked by
miksh
Top achievements
Rank 1
Iron
Answers by
Princy
Top achievements
Rank 2
miksh
Top achievements
Rank 1
Iron
Eyup
Telerik team
Share this question
or