Hello,
I have a Prometheus grid with AutoGeneratedDeleteColumn and I am wondering if there is a direct way to attach rad window or alert popup on the delete button click event, so when a user clicks delete to get alert message.
Thanks,
Ivo
1 Answer, 1 is accepted
0
Hi Ivo,
For your convenience I have prepared a small demo which illustrates how to attach radconfirm dialog to AutoGeneratedDeleteColumn in RadGrid. Here are the relevant code snippets:
Review the attached project for further details. Note that you will need to change the server name in the web.config file to point to your SQL server instance.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
For your convenience I have prepared a small demo which illustrates how to attach radconfirm dialog to AutoGeneratedDeleteColumn in RadGrid. Here are the relevant code snippets:
| <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> |
| <script type="text/javascript"> |
| var oldConfirm = radconfirm; |
| window.radconfirm = function(text, mozEvent) |
| { |
| var ev = mozEvent ? mozEvent : window.event; //Moz support requires passing the event argument manually |
| //Cancel the event |
| ev.cancelBubble = true; |
| ev.returnValue = false; |
| if (ev.stopPropagation) ev.stopPropagation(); |
| if (ev.preventDefault) ev.preventDefault(); |
| //Determine who is the caller |
| var callerObj = ev.srcElement ? ev.srcElement : ev.target; |
| //Call the original radconfirm and pass it all necessary parameters |
| if (callerObj) |
| { |
| //Show the confirm, then when it is closing, if returned value was true, automatically call the caller's click method again. |
| var callBackFn = function (arg) |
| { |
| if (arg) |
| { |
| callerObj["onclick"] = ""; |
| if (callerObj.click) callerObj.click(); //Works fine every time in IE, but does not work for links in Moz |
| else if (callerObj.tagName == "A") //We assume it is a link button! |
| { |
| try |
| { |
| eval(callerObj.href) |
| } |
| catch(e){} |
| } |
| } |
| } |
| oldConfirm(text, callBackFn, 300, 100, null); |
| } |
| return false; |
| } |
| </script> |
| </telerik:RadCodeBlock> |
| <asp:ScriptManager ID="ScriptManager1" runat="server" /> |
| <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="RadGrid1"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManager> |
| <telerik:RadWindowManager ID="WindowManager1" runat="server" /> |
| <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AllowSorting="True" |
| ShowStatusBar="true" GridLines="None" Width="95%" AutoGenerateDeleteColumn="true"> |
| <MasterTableView Width="100%" DataKeyNames="EmployeeID" AllowAutomaticDeletes="true" /> |
| </telerik:RadGrid> |
| <br /> |
| <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" |
| ProviderName="System.Data.SqlClient" |
| SelectCommand="SELECT EmployeeID, LastName, FirstName, Title, City FROM Employees" |
| DeleteCommand="DELETE from Employees WHERE EmployeeID = @EmployeeID" |
| runat="server"> |
| <DeleteParameters> |
| <asp:Parameter Name="EmployeeID" Type="int32" /> |
| </DeleteParameters> |
| </asp:SqlDataSource> |
| Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated |
| If TypeOf e.Item Is GridDataItem Then |
| Dim deleteButton As LinkButton = CType(CType(e.Item, GridDataItem)(RadGrid1.MasterTableView.RenderColumns(2).UniqueName).Controls(0), LinkButton) |
| deleteButton.Attributes("onclick") = "return radconfirm('Are you sure you want to delete this record?')" |
| End If |
| End Sub |
Review the attached project for further details. Note that you will need to change the server name in the web.config file to point to your SQL server instance.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center