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

[Solved] RadAjaxPanel does not update grid after deleting an item

2 Answers 139 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Jen
Top achievements
Rank 1
Jen asked on 29 Apr 2009, 01:49 PM

I have a grid that does not update automaticly after I deleted an item. However, if I click on the refresh button, the item has been removed from de grid. I placed the grid in a RadAjaxLoadingPanel, but it's not working. Can someone help me?
This is my ascx code:

<%@ Control language="vb" Inherits="BDB.Modules.BDB_Promo_Settings.ViewBDB_Promo_Settings" CodeFile="ViewBDB_Promo_Settings.ascx.vb" AutoEventWireup="false" Explicit="True" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<%@ Register TagPrefix="dnn" TagName="Audit" Src="~/controls/ModuleAuditControl.ascx" %> 
     
<telerik:RadAjaxLoadingPanel ID="radLoadingPromo" runat="server" Height="75px" Width="75px">  
    <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' 
        style="border: 0px;" /> 
</telerik:RadAjaxLoadingPanel> 
 
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Height="100%" Width="100%" EnableAJAX="true" LoadingPanelID="radLoadingPromo">  
<telerik:RadGrid ID="gridPromo" runat="server" AutoGenerateColumns="False" EnableAJAX="true" 
    GridLines="None" AllowAutomaticDeletes="true" OnDeleteCommand="gridPromo_DeleteCommand" 
    EnableEmbeddedSkins="False" Skin="BDB">  
<HeaderContextMenu EnableTheming="True">  
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
</HeaderContextMenu> 
 
<MasterTableView> 
<RowIndicatorColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</RowIndicatorColumn> 
 
<ExpandCollapseColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</ExpandCollapseColumn> 
    <Columns> 
        <telerik:GridBoundColumn DataField="PromoId" HeaderText="ID" UniqueName="ID"   
            Visible="False">  
        </telerik:GridBoundColumn> 
        <telerik:GridTemplateColumn HeaderText="Afbeelding" UniqueName="Afbeelding" DataField="Folder">  
            <ItemTemplate> 
                <asp:Image ID="afbPromo" runat="server" /> 
            </ItemTemplate> 
        </telerik:GridTemplateColumn> 
        <telerik:GridBoundColumn DataField="Alt" HeaderText="Alt" UniqueName="Alt">  
        </telerik:GridBoundColumn> 
        <telerik:GridButtonColumn ConfirmText="Wilt u deze afbeelding verwijderen?" ButtonType="ImageButton" ImageUrl="~/images/action_delete.gif" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" >              
        </telerik:GridButtonColumn> 
        <telerik:GridBoundColumn DataField="Folder" HeaderText="Folder"   
            UniqueName="Folder" Visible="False">  
        </telerik:GridBoundColumn> 
    </Columns> 
    <EditFormSettings> 
        <EditColumn CancelImageUrl="Cancel.gif" EditImageUrl="Edit.gif"   
            InsertImageUrl="Update.gif" UpdateImageUrl="Update.gif">  
        </EditColumn> 
    </EditFormSettings> 
</MasterTableView> 
 
<FilterMenu EnableTheming="True">  
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
</FilterMenu> 
</telerik:RadGrid> 
 
<br /> 
<span style="float:right">  
    <asp:ImageButton ID="imgbuRefresh" ImageUrl="~/images/action_refresh.gif" runat="server" />&nbsp;  
    <asp:ImageButton ID="imgBuAdd" ImageUrl="~/Portals/_default/Skins/BDB-Blue/images/add.gif" runat="server" />       
</span> 
</telerik:RadAjaxPanel> 
 
<telerik:RadWindowManager ID="windowMgrPromo" runat="server" Animation="Resize"   
    DestroyOnClose="True">  
<Windows> 
<telerik:RadWindow ID="windowPromo" runat="server" Skin="Forest" NavigateUrl="PromoUpload.aspx" VisibleStatusbar="False" VisibleTitlebar="True" Height="300" Width="700">  
</telerik:RadWindow> 
<telerik:RadWindow ID="windowMessage" runat="server"></telerik:RadWindow> 
</Windows> 
</telerik:RadWindowManager> 
<asp:Label ID="lblTest" runat="server"></asp:Label> 
 
 

And this is my code-behind:
'  
' DotNetNuke® - http://www.dotnetnuke.com  
' Copyright (c) 2002-2006  
' by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )  
'  
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated   
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation   
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and   
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:  
'  
' The above copyright notice and this permission notice shall be included in all copies or substantial portions   
' of the Software.  
'  
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED   
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL   
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF   
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER   
' DEALINGS IN THE SOFTWARE.  
'  
Imports DotNetNuke  
Imports System.Web.UI  
Imports System.Collections.Generic  
Imports System.Reflection  
Imports Telerik.Web.UI  
Imports System.IO  
 
Namespace BDB.Modules.BDB_Promo_Settings  
 
    ''' -----------------------------------------------------------------------------  
    ''' <summary>  
    ''' The ViewDynamicModule class displays the content  
    ''' </summary>  
    ''' <remarks>  
    ''' </remarks>  
    ''' <history>  
    ''' </history>  
    ''' -----------------------------------------------------------------------------  
    Partial Class ViewBDB_Promo_Settings  
        Inherits Entities.Modules.PortalModuleBase  
        Implements Entities.Modules.IActionable
#Region "Private Members"  
        Private colBDB_Promo_Settings As List(Of BDB_Promo_SettingsInfo)
#End Region  
 
#Region "Event Handlers" 
 
        ''' -----------------------------------------------------------------------------  
        ''' <summary>  
        ''' Page_Load runs when the control is loaded  
        ''' </summary>  
        ''' <remarks>  
        ''' </remarks>  
        ''' <history>  
        ''' </history>  
        ''' -----------------------------------------------------------------------------  
        Private Sub Page_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
            Dim _controller As New BDB_Promo_SettingsController  
            colBDB_Promo_Settings = _controller.GetAllBDB_Promo_Settings()  
            windowPromo.VisibleOnPageLoad = True 
            windowPromo.Visible = False 
        End Sub 
        Protected Sub imgBuAdd_Click(ByVal sender As ObjectByVal e As System.Web.UI.ImageClickEventArgs) Handles imgBuAdd.Click              
            windowPromo.Visible = True 
        End Sub 
        Protected Sub imgbuRefresh_Click(ByVal sender As ObjectByVal e As System.Web.UI.ImageClickEventArgs) Handles imgbuRefresh.Click  
            gridPromo.DataSource = colBDB_Promo_Settings  
            gridPromo.DataBind()  
        End Sub 
        Protected Sub gridPromo_DeleteCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles gridPromo.DeleteCommand  
            If (e.CommandName = "Delete"Then 
                Try 
                    ' Remove record from database  
                    Dim data As GridDataItem  
                    data = e.Item  
 
                    Dim _controller As New BDB_Promo_SettingsController  
                    _controller.DeleteBDB_Promo_Settings(CType(data.Item("ID").Text, Integer))  
 
                    ' Remove image from hard disk  
                    If File.Exists(data.Item("Folder").Text) Then 
                        File.Delete(data.Item("Folder").Text)  
                    End If 
 
                    gridPromo.Rebind()  
 
                    lblTest.Text = "De afbeelding is verwijderd." 
                    lblTest.Visible = True 
                Catch ex As Exception  
                    lblTest.Text = "Er is een fout opgetreden bij het verwijderen van de afbeelding." 
                    lblTest.Visible = True 
                End Try 
 
            End If 
        End Sub 
        Protected Sub gridPromo_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles gridPromo.NeedDataSource  
            gridPromo.DataSource = colBDB_Promo_Settings  
            'gridPromo.DataBind()  
        End Sub 
        Protected Sub gridPromo_PreRender(ByVal sender As ObjectByVal e As System.EventArgs) Handles gridPromo.PreRender  
            Dim gridRows As GridItemCollection = gridPromo.Items  
            Dim obj As BDB.Modules.BDB_Promo_Settings.BDB_Promo_SettingsInfo  
            Dim afbeelding As System.Web.UI.WebControls.Image  
 
            Try 
                For Each data As GridDataItem In gridRows  
                    obj = data.DataItem  
                    afbeelding = CType(data.FindControl("afbPromo"), System.Web.UI.WebControls.Image)  
                    afbeelding.ImageUrl = obj.Lokatie  
                    afbeelding.ToolTip = obj.Alt  
                    'afbeelding.Height = 100  
                    'afbeelding.Width = 400  
                Next 
            Catch ex As Exception  
 
            End Try 
 
        End Sub
#End Region  
 
#Region "Optional Interfaces" 
 
        ''' -----------------------------------------------------------------------------  
        ''' <summary>  
        ''' Registers the module actions required for interfacing with the portal framework  
        ''' </summary>  
        ''' <value></value>  
        ''' <returns></returns>  
        ''' <remarks></remarks>  
        ''' <history>  
        ''' </history>  
        ''' -----------------------------------------------------------------------------  
        Public ReadOnly Property ModuleActions() As Entities.Modules.Actions.ModuleActionCollection Implements Entities.Modules.IActionable.ModuleActions  
            Get 
                Dim Actions As New Entities.Modules.Actions.ModuleActionCollection  
                Actions.Add(GetNextActionID, Localization.GetString(Entities.Modules.Actions.ModuleActionType.AddContent, LocalResourceFile), Entities.Modules.Actions.ModuleActionType.AddContent, """", EditUrl(), False, Security.SecurityAccessLevel.Edit, TrueFalse)  
                Return Actions  
            End Get 
        End Property
#End Region  
    End Class 
End Namespace 

2 Answers, 1 is accepted

Sort by
0
Todd
Telerik team
answered on 04 May 2009, 05:22 PM
Hi Jennifer,

Sorry to hear you're having trouble with RadGrid deletes. For the most part, your code looks like it should work. There are a few uncessary items and things that can be optimized:
  • There is no longer an "EnableAJAX" property on RadGrid (this code be removed)
  • "AllowAutomaticDeletes" only works with Data Soruce controls, not with manual data binding
  • It is uncessary to explicitly call "DataBind()" in your Delete handler - this will happen automatically
That said, none of these items should affect your Grid's ability to update with Ajax after a delete.

I have built and attached a simple demo project showing a RadGrid with a GridButtonColumn performing a delete as you are in your example. Please review this demo and see if it helps. Let me know if you have any additional questions. 

Sincerely yours,
Todd
0
Jen
Top achievements
Rank 1
answered on 07 May 2009, 07:40 AM

Hello Todd,

 

Thank you for your response. I've got it working by adding the following code to the init event (I'm using DNN):

If DotNetNuke.Framework.AJAX.IsInstalled Then 
    DotNetNuke.Framework.AJAX.RegisterScriptManager()  
End If 

I also deleted the unnecessary items you mentioned.
Tags
Ajax
Asked by
Jen
Top achievements
Rank 1
Answers by
Todd
Telerik team
Jen
Top achievements
Rank 1
Share this question
or