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

Dynamically set ConfirmText on GridButtonColumn

26 Answers 1427 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 12 Jul 2010, 03:05 PM
Hello,

I have a RadGrid with a GridButtonColumn.  I have messages in a table in my database that I want to display instead of hard-coding the message in the ConfirmText property in the designer.  How do I go about setting the ConfirmText property dynamically?

I attempted to find the GridButtonColumn in the OnItemDataBound event, but received a message that a control cannot be cast as a GridButtonColumn.

Thanks,

26 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 12 Jul 2010, 03:11 PM
Hello Tom,

You can do so in the OnPreRender event of the Page as follows (beforehand, you need to set the UniqueName property of the column):

protected override void OnPreRender(EventArgs e) 
    base.OnPreRender(e); 
    ((GridButtonColumn)RadGrid1.MasterTableView.GetColumnSafe("YourColumnUniqueName")).ConfirmText = "your confirm dialogue text."
}

Hope it helps.

All the best,
Tsvetoslav
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
Tom
Top achievements
Rank 1
answered on 12 Jul 2010, 06:06 PM
Tsvetoslav,

Thanks for the quick reply.  I implemented the page OnPreRender event as shown, but there is no popup now (as compared to using the ConfirmText in the designer of the radgrid).  Do you have any ideas on why I am not seeing the popup?

Thanks,
0
Tsvetoslav
Telerik team
answered on 14 Jul 2010, 09:52 AM
Hi Tom,

Attached is a small sample that should give you more information.

All the best,
Tsvetoslav
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
Jonx
Top achievements
Rank 2
answered on 25 Jan 2011, 05:08 PM
Hello Tsvetoslav,
If I'm correct what you suggest does set the same text for all the buttons...

But what I need is to set custom text for each button.

Right now I'm using the following which is working how I want, just I want to use radwindow instead of the standard web browser dialog:
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem dataItem = e.Item as GridDataItem;
                string contactName = dataItem["Nom"].Text;
 
                ImageButton button = dataItem["colDelete"].Controls[0] as ImageButton;
                button.Attributes["onclick"] = "return confirm('Etes vous sur de vouloir suprimer le stagiaire \"" +
                contactName + "\" ?')";
            }
        }

It would be really nice if I could set the confirmtext to:
ConfirmText="Suppress the student with name: {0}?" and tell somewhere else that it should use the value from a given field... That way I would have nothing to do ;)

Any idea? Thanks a lot in advance,
John.

0
Tsvetoslav
Telerik team
answered on 31 Jan 2011, 10:23 AM
Hi John,

Your approach is correct and valid. If you need to display a RadWindow confirm dialogue, you need to place a RadWindowManager control on the page - sorry for having missed this detail in my sample.

Do let us know if you need further assistance.

Regards,
Tsvetoslav
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Jonx
Top achievements
Rank 2
answered on 31 Jan 2011, 10:47 AM
Hello...
Thank you for your help but I'm not sure to get you...

Let me rephrase my problem...

I have a grid with a column to let me delete entries in my grid.

Before deleting something, I want a RadWindow to confirm my deletion.

I'm using this to achieve my goal:
<telerik:GridButtonColumn ConfirmText="Delete that entry?" ConfirmDialogType="RadWindow"  HeaderStyle-Width="30px" ConfirmTitle="Sure?" ButtonType="ImageButton" ImageUrl="Images/ok.png" CommandName="Delete" Text="Delete the entry" UniqueName="colDelete" />

The problem is that I want to customize the text so that I can include the name of the item that I want to delete.

Instead of displaying "Delete that entry?" I want to display "Delete entry 'John' "...

How can I do that with a telerik:GridButtonColumn and a RadWindow?

dataItem["colDelete"] gives me a GridTableCell.

dataItem["colValider"].Controls[0] gives me an ImageButton...

How can I access to the ConfirmText of the current row to be able to customize it...

Thank you for you help,
John.

0
Shinu
Top achievements
Rank 2
answered on 31 Jan 2011, 01:14 PM
Hello John,

Please take a look at the following forum which also discusses the similar scenario. Hope it will help.
GridButtonColumn, RadWindow and ConfirmText

-Shinu.
0
Jonx
Top achievements
Rank 2
answered on 31 Jan 2011, 09:32 PM
Hello shinu,
Thanks you for your help.
You are right, that should work but I prefer a server side solution.

I'm sure there must be a way to access to that ConfirmText property...

Anyone ?

Thanks again,
John.
0
Princy
Top achievements
Rank 2
answered on 03 Feb 2011, 12:16 PM
Hello John,

Try the following code snippet to achieve this.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
           GridDataItem dataItem = e.Item as GridDataItem;
            string contactName = dataItem["Nom"].Text;
            (RadGrid1.MasterTableView.GetColumn("colDelete") as GridButtonColumn).ConfirmText = "Delete    "+contactName;
         }
    }

Thanks,
Princy.
0
Stephen
Top achievements
Rank 1
answered on 10 Feb 2011, 10:41 PM
When I use the code below and change the ConfirmText in the ItemDataBound, it is setting it for the next row, not the current row.  Is there a bug or am I doing something wrong?
0
Sebastian
Telerik team
answered on 11 Feb 2011, 09:46 AM
Hello Stephen,

I tested the code slice provided by Princy and it worked as expected - the confirm text is set for the button in the same row since the same GridDataItem (e.Item) is referenced. I suggest you debug your code to trace the code execution, this can help idenfity the cause of the abnormality to eliminate it.
 
Kind regards,
Sebastian
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Jonx
Top achievements
Rank 2
answered on 12 Feb 2011, 03:00 AM
Hello Sebastian,

I have to agree with Stephen, the number is off one row...

I would be interested in seeing your working sample.

Let me explain what I understand from the tips suggested by Princy (thanks Princy by the way for helping out here and there;) )
correct me if I'm wrong.

This 
(RadGrid1.MasterTableView.GetColumn("colDelete") as GridButtonColumn).ConfirmText = "Delete    "+contactName;
gives me access to the column, not to the current controls in the current row cell...

Also we are in the _ItemDataBound event.

So my gessing is that setting the ConfirmText here comes to late in the grid rendering to be used correctly for the delete button.

That's why it's only used in the next row.

I tried in _ItemCreated but it's not working either.

The hint that proves my theory is that the first line of the grid has an empty ConfirmText and all the other lines are of by one line...

Now, I may be wrong... in my sample, I have to columns to help test my delete scenario :
//build custom delete message
string contactName = dataItem["SessionID"].Text;
 // using standard javascript
ImageButton btnDelete = dataItem["colDelete"].Controls[0] as ImageButton;
btnDelete.Attributes["onclick"] = "return confirm('Etes vous sur de vouloir suprimer la session N° : " +
contactName + " ?')";
 //using the radwindow
GridButtonColumn btnOldDelete = RadGrid1.MasterTableView.GetColumn("oldDelete") as GridButtonColumn;
btnOldDelete.ConfirmText = "Etes vous sur de vouloir suprimer la session N° : " + contactName;

The first version does display the correct text, the second is one row off...

Anyway,
Thank you for your help guys, what do you think?
John.
0
Sebastian
Telerik team
answered on 14 Feb 2011, 10:28 AM
Hi guys,

Indeed John is right - please excuse me if my previous response was misleading for you. I actually tested the code setting onclick attribute for the button inside the GridDataItem as John posted previously in this thread. This is 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).

Using the ConfirmText property of the GridButtonColumn is applicable for specifying a common (row context independent) confirm text for each of the buttons in that column.

Kind regards,
Sebastian
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Jonx
Top achievements
Rank 2
answered on 14 Feb 2011, 10:41 AM
Hello Sebastian,
Sorry to insist...
But the interest in using the ConfirmText property of the GridButtonColumn is that this uses a RadWindow whereas the other way is using the default browser dialog. And what I want to use it the RadWindow to ask confirmation...
Is there something that can be done for that?
Use a RadWindow with custom text for each row of my grid?
This would be really nice because as you probably know, the dialogs in IE make a noisy bit and this is a real pain for my users...
Thanks yo for your help,
John.  
0
Sebastian
Telerik team
answered on 14 Feb 2011, 11:00 AM
Hello John,

I see your point here. If you prefer to use RadWindow for confirm dialog on a per-row basis, consider the implementation presented in this KB article.

Best regards,
Sebastian
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Jonx
Top achievements
Rank 2
answered on 14 Feb 2011, 11:18 AM
Hum I see...
This all seems like overkill for such a simple task.
Too bad since all we need is there, just we don't have access to it...

Would you consider adding the following feature to your framework by allowing the following syntax for the GridButtonColum?

<telerik:GridButtonColumn ConfirmText="Delete entry '{0}'?" Field="Name"
ConfirmDialogType="RadWindow"  ConfirmTitle="Sure?" CommandName="Delete" UniqueName="colDelete" />

So that you would automaticaly insert the row field Name in place of the {0}?
This would solve the problem very easily at the column level.

What do you think?
John.
0
Marin
Telerik team
answered on 17 Feb 2011, 05:23 PM
Hello John,

Thank you for the suggestion.

We will do our best to implement this feature for the next major release of RadControls.

Best wishes,
Marin
the Telerik team
0
Jonx
Top achievements
Rank 2
answered on 17 Feb 2011, 05:36 PM
Good to hear... thanks.

But until then? What can I do?

Is the only way to it (have custom text with radwindow), to use the solution suggested by Shinu here?
http://www.telerik.com/community/forums/aspnet-ajax/grid/gridbuttoncolumn-radwindow-and-confirmtext.aspx

-John
0
Sebastian
Telerik team
answered on 18 Feb 2011, 12:20 PM
Hello John,

Yes, the current options you have are described in this thread. Note that the next major release (Q1 2011) of our AJAX suite is scheduled in the middle of March and a Beta version of it is expected to roll out at the end of the next week.

Greetings,
Sebastian
the Telerik team
0
Jonx
Top achievements
Rank 2
answered on 18 Feb 2011, 12:22 PM
Great. I'll keep an eye on it and make sure to test and use the featue when it comes out.
Thanks for your help,
John.
0
Javier
Top achievements
Rank 1
answered on 09 Mar 2011, 08:13 PM
I don't know if this will be of any use to you anymore, but I found an easy way to customize the confirm text per row.

The records I pull can either be active or inactive.  The "delete" button will just reverse the state.
I wanted a relevant popup to alert the user of which state he's about to convert to.

On the DataBound event of the grid itself I call a function called setDeactiveText().  


Private Sub setDeactivateText()
   For i As Integer = 1 To rgdReportTemplates.Items.Count - 1
       If rgdReportTemplates.Items(i).GetDataKeyValue("Active") Then
           DirectCast(rgdReportTemplates.Items(i).Item("DeleteColumn").Controls(0), ImageButton).Attributes("onclick") = "if(!$find('rgdReportTemplates').confirm('Are you sure you want to set the record to INACTIVE?', event, 'Delete'))return false;"
       Else
           DirectCast(rgdReportTemplates.Items(i).Item("DeleteColumn").Controls(0), ImageButton).Attributes("onclick") = "if(!$find('rgdReportTemplates').confirm('Are you sure you want to set the record to ACTIVE?', event, 'Delete'))return false;"
       End If
   Next
End Sub


 Basically I just update the onclick event of the imagebutton.  I pulled the javascript from a rendered page with a different message.

rgdReportTemplates is the radgrid name
DeleteColumn is the UniqueName for the GridButtonColumn

Javier
0
Robin
Top achievements
Rank 1
answered on 16 Aug 2011, 04:44 AM
Yes, I have to agree. This worked for me too:

protected void AlternateEmailsRadGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
    //Get the row from the grid.
    GridDataItem dataItem = e.Item as GridDataItem;
    if (dataItem != null)
    {
        // Delete //
        ImageButton button = dataItem["DeleteColumn"].Controls[0] as ImageButton;
        button.Attributes["onclick"] = string.Format("return confirm(\"{0}\");", string.Format(Resources.Messages.MESSAGE_DELETE_EMAIL_ADDRESS_CONFIRMATION, dataItem["Email"].Text));
    }
}

Good luck!
0
Jean-Francois
Top achievements
Rank 1
answered on 22 Aug 2013, 03:06 PM
Just remove the "If TypeOf e.Item Is GridDataItem Then" check.  All your lines will be set correctly.

With the "Trycast" method, it will take care of itself, you don't need to check if it's a GridDataItem.

This is what I did and it worked great for all lines (I had the same problem by the way):

Private Sub trgWEB_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles trgWEB.ItemDataBound
            TryCast(trgWEB.MasterTableView.GetColumn("trgWEB_Delete"), GridButtonColumn).ConfirmText = "Delete?"
            'If TypeOf e.Item Is GridDataItem Then
            'End If
End Sub

0
Terrah Mthombeni
Top achievements
Rank 1
answered on 12 Feb 2014, 07:13 AM
Thanks for leading me to the solution.
0
Waqas Aslam
Top achievements
Rank 2
answered on 26 Sep 2014, 01:52 AM
Now you may add dynamic dialog message using the following:

<telerik:GridButtonColumn CommandName="Delete" UniqueName="Delete" ButtonType="ImageButton"
     ImageUrl="~/Images/NavIcons/cross.png" ConfirmDialogType="RadWindow"
     ConfirmTextFields="OrderId" ConfirmTextFormatString="Are you sure you want to delete order# {0}?"
     ConfirmTitle="Delete Order!"></telerik:GridButtonColumn>


*OrderId is a DataField which will insert its value at TextFormat {0}
0
Corin
Top achievements
Rank 1
answered on 03 Nov 2017, 01:53 PM

I think I got it. When I'm creating the button, I set the confirm text for the column to something easy to find. I've used "############" but I guess it could be anything. 

In my Grid_ItemDataBound:

1.Private Const DummyConfirmText As String = "#############" 'use this for your confirm text
2.Dim theGridButtonColumn = CType(_mygrid.MasterTableView.GetColumn("cmdInvestigation"), GridButtonColumn)
3.Dim theGridButtonControl As Button = TryCast(item.Cells(theGridButtonColumn.OrderIndex).Controls(0), Button)
4.theGridButtonControl.Attributes("onclick") = theGridButtonControl.Attributes("onclick").Replace(DummyConfirmText, "Giraffe Giraffe Giraffe")
Tags
Grid
Asked by
Tom
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Tom
Top achievements
Rank 1
Jonx
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Stephen
Top achievements
Rank 1
Sebastian
Telerik team
Marin
Telerik team
Javier
Top achievements
Rank 1
Robin
Top achievements
Rank 1
Jean-Francois
Top achievements
Rank 1
Terrah Mthombeni
Top achievements
Rank 1
Waqas Aslam
Top achievements
Rank 2
Corin
Top achievements
Rank 1
Share this question
or