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

[Solved] RadGrid Refresh and Delete not working inside popup

8 Answers 227 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RB
Top achievements
Rank 1
RB asked on 16 Jun 2014, 09:24 PM
I have a Radgrid which is part of a popup window. the popup window has a panel which has an update panel to which the radgrid is added. The refresh and delete do not work here because the RadGrid1_ItemCommand is never invoked! Whereas if I add the same control, without the popup it works fine.

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Jun 2014, 06:53 AM
Hi,

Please have a look into the sample code snippet which works fine at my end. Please provide your full code if it doesn't help.

ASPX:
<telerik:RadWindow ID="rwindowPopUp" runat="server" VisibleOnPageLoad="true">
    <ContentTemplate>
        <asp:UpdatePanel ID="updatepnlGrid" runat="server">
            <ContentTemplate>
                <telerik:RadGrid ID="rgrdOrders" runat="server" DataSourceID="sqldsOrders" CellSpacing="-1" GridLines="Both" OnItemCommand="rgrdOrders_ItemCommand">
                    <MasterTableView DataSourceID="sqldsOrders" AutoGenerateColumns="False" CommandItemDisplay="Top" DataKeyNames="OrderID">
                        <Columns>
                            <telerik:GridBoundColumn DataField="OrderID" DataType="System.Int32" FilterControlAltText="Filter OrderID column" HeaderText="OrderID" ReadOnly="True" SortExpression="OrderID" UniqueName="OrderID">
                            </telerik:GridBoundColumn>
                        </Columns>
                    </MasterTableView>
                </telerik:RadGrid>
                <asp:SqlDataSource ID="sqldsOrders" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [OrderID], [CustomerID] FROM [Orders]"></asp:SqlDataSource>
            </ContentTemplate>
        </asp:UpdatePanel>
    </ContentTemplate>
</telerik:RadWindow>

C#:
protected void rgrdOrders_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == "RebindGrid")
    {
        //your code
    }
}

Thanks,
Princy.
0
RB
Top achievements
Rank 1
answered on 23 Jun 2014, 09:39 PM
public class DocumentumDocumentListGrid : WebControl
{
    #region Fields      
   
    private EntityTable _EntityDocumentumReferenceTable = null;
    private RadAjaxLoadingPanel _RadLoadingPanel = new RadAjaxLoadingPanel();
    private UpdatePanel _UpdatePanel = new UpdatePanel();
    private RadGrid _RadGrid1 = new RadGrid();     
    private bool _LoadListByQuoteId;
    private int _QuoteId = 0;
    private int _EntityId;
    private string _EntityType;
    private bool _IsError = false;
    private int _CatalogProductId;
    private string _ErrorMessage = string.Empty;
    private bool _ShowModify = false; // This functionality is not intuitive on the Documentum side; leaving it out until further notice.
    private string _DocumentId = string.Empty;
 
    public event DocumentDeletedEventHandler DocumentDeleted = null;
    public event DocumentErrorEventHandler DocumentError = null;
 
    #endregion    
 
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        LoadDocumentList();
         
        this._RadLoadingPanel.ID = "_RadLoadingPanel";
        this._RadLoadingPanel.Transparency = 30;
        this._RadLoadingPanel.Skin = "WebBlue";
        this._RadLoadingPanel.BackgroundPosition = AjaxLoadingPanelBackgroundPosition.Center;
         
        #region Grid1
        this._RadGrid1.ID = "RadGrid1";
        this._RadGrid1.Skin = "WebBlue";
        this._RadGrid1.Width = Unit.Percentage(100);
        this._RadGrid1.GridLines = GridLines.None;
        this._RadGrid1.AllowSorting = true;
        this._RadGrid1.AllowFilteringByColumn = false;
        this._RadGrid1.ShowGroupPanel = false;
        this._RadGrid1.AutoGenerateColumns = false;
        this._RadGrid1.AutoGenerateDeleteColumn = false;
        this._RadGrid1.AllowPaging = false;
        this._RadGrid1.EnableLinqExpressions = false;
        this._RadGrid1.MasterTableView.NoMasterRecordsText = "There are no documents associated with this order / quote / proposal.";      
        this._RadGrid1.ClientSettings.Selecting.AllowRowSelect = false;
        this._RadGrid1.ClientSettings.EnableRowHoverStyle = true;
        this._RadGrid1.ClientSettings.EnablePostBackOnRowClick = false;
        this._RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;
        this._RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;   
        this._RadGrid1.MasterTableView.DataKeyNames = new string[] { this._EntityTable.EntityDocumentumReferenceIdColumn.ColumnName };           
         
        this._RadGrid1.NeedDataSource += RadGrid1_NeedDataSource;
        this._RadGrid1.ItemDataBound += RadGrid1_ItemDataBound;
        this._RadGrid1.ItemCommand += RadGrid1_ItemCommand;
         
        
        #region Columns
 
        GridBoundColumn boundColumn = new GridBoundColumn();
 
        string templateColumnName = "Modify";
        GridTemplateColumn templateColumn = new GridTemplateColumn();
        templateColumn.ItemTemplate = new CheckBoxTemplate(templateColumnName);
        templateColumn.HeaderText = templateColumnName;
        templateColumn.AllowFiltering = false;
        templateColumn.HeaderStyle.CssClass = "GXDataGridHeader";
        templateColumn.SortExpression = "";        
        templateColumn.DataField = this._EntityTable.DocumentIdColumn.ColumnName;          
        templateColumn.Visible = (_ShowModify && !this.IsReadOnly);
        this._RadGrid1.MasterTableView.Columns.Add(templateColumn);
 
        GridHyperLinkColumn hyperLinkColumn = new GridHyperLinkColumn();
        hyperLinkColumn.DataNavigateUrlFields = new string[] { this._EntityTable.DocumentUrlColumn.ColumnName };
        hyperLinkColumn.SortExpression = this._EntityTable.DocumentNameColumn.ColumnName;
        hyperLinkColumn.DataTextField = this._EntityTable.DocumentNameColumn.ColumnName;
        hyperLinkColumn.HeaderText = "Document Name";
        hyperLinkColumn.ItemStyle.CssClass = "GridLinkButton";
        hyperLinkColumn.Target = "_Blank";
        hyperLinkColumn.ItemStyle.Width = Unit.Pixel(500);
        hyperLinkColumn.ItemStyle.Wrap = true;
        hyperLinkColumn.AllowFiltering = false;
        hyperLinkColumn.UniqueName = "DocumentName";
        this._RadGrid1.MasterTableView.Columns.Add(hyperLinkColumn);
 
        //documentum ID (hidden)
        boundColumn = new GridBoundColumn();
        this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = this._EntityTable.DocumentIdColumn.ColumnName;
        boundColumn.SortExpression = this._EntityTable.DocumentIdColumn.ColumnName;
        boundColumn.HeaderText = "Document ID";
        boundColumn.Visible = false;
        
        //documentType          
        boundColumn = new GridBoundColumn();          
        this._RadGrid1.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = this._EntityTable.DescriptionColumn.ColumnName;
        boundColumn.SortExpression = this._EntityTable.DescriptionColumn.ColumnName;
        boundColumn.HeaderText = "Document Type";
        boundColumn.UniqueName = "DocumentType";
        if (this.ShowDocumentType)
        {
            boundColumn.Visible = true;
        }
        else
        {
            boundColumn.Visible = false;
        }           
        if (this.ShowDelete)
        {
            GridButtonColumn buttonColumn = new GridButtonColumn();
            _RadGrid1.MasterTableView.Columns.Add(buttonColumn);
            buttonColumn.DataTextField = this._EntityTable.DocumentIdColumn.ColumnName;                               
            buttonColumn.HeaderText = "Delete";
            buttonColumn.UniqueName = "DeleteColumn";
            buttonColumn.ButtonType = GridButtonColumnType.ImageButton;
            buttonColumn.ImageUrl = this.ResolveUrl("/ucommand/CRM/images/") + "Delete.gif";
            buttonColumn.ConfirmText = "Delete Document?";
            buttonColumn.CommandName = "DeleteDocument";
            buttonColumn.HeaderStyle.Width = Unit.Pixel(50);
        }         
        #endregion
 
        #endregion
 
        this._UpdatePanel.UpdateMode = UpdatePanelUpdateMode.Conditional;
        this._UpdatePanel.ContentTemplateContainer.Controls.Add(this._RadLoadingPanel);
        this._UpdatePanel.ContentTemplateContainer.Controls.Add(this._RadGrid1);
        this.Controls.Add(this._UpdatePanel);          
    }
 
   
 
    #endregion
 
    #region Events
 
    public void Refresh()
    {
        this._RadGrid1.Rebind();
    }
    void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
 
        LoadDocumentList();
        this._RadGrid1.DataSource = _EntityDocumentumReferenceTable;
    }    
 
    /// <summary>
    /// event for Delete and refresh button
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>    
 
    void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.RebindGridCommandName)
        {
            .
            .
            .
            .
        }
 
        #region delete document
        if (e.CommandName == "DeleteDocument")
        {
           .
           .
           .
            this._RadGrid1.Rebind();               
        }
        #endregion delete document
        
    }
    private void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        //Manipulate UI if file in queue
        if (e.Item is GridDataItem)
        {
         
 
        }
 
    }
    #endregion Events
    protected override void OnPreRender(EventArgs e)
    {       
        base.OnPreRender(e);
        RadAjaxManager ajaxManager = RadAjaxManager.GetCurrent(Page);
        ajaxManager.AjaxSettings.AddAjaxSetting(this._UpdatePanel, this._RadGrid1, this._RadLoadingPanel);         
    }
  
    #region Private Methods
    /// <summary>
    /// get an Id for errors
    /// </summary>
    /// <returns></returns>
    private string GetUniqueId()
    {
        if (!string.IsNullOrEmpty(this._DocumentId))
            return " DocumentId: " + this._DocumentId;
 
        if (this._QuoteId != 0)
            return " QuoteId: " + this._QuoteId.ToString();
 
        if (this._EntityId != 0)
            return " EntityId: " + this._EntityId.ToString();
 
        return string.Empty;
    }
 
    /// <summary>
    /// set the error objects
    /// </summary>
    /// <param name="documentId"></param>
    /// <param name="message"></param>
    private void SetError(string documentId, string message)
    {
        this._IsError = true;
        this._ErrorMessage = message;
        if (this.DocumentError != null)
        {
            DocumentError(this, new DocumentErrorArgs(documentId, message));
        }          
    }
 
    private void LoadDocumentList()
    {
        
         _EntityDocumentumReferenceTable = new EntityReferenceTable_ListByEntityId().ExecuteTypedDataTable(_EntityId, _EntityType);
         
    }
 
    
 
    #endregion
}

Above is the full code. I have used the same control at other pages which are not a poopup and it works good. But when I use this same control inside a popup, it fails to call the RadGrid1_ItemCommand!
0
RB
Top achievements
Rank 1
answered on 23 Jun 2014, 10:59 PM
I also observed that though I have buttonColumn.ConfirmText = "Delete Document?"; this popup is never displayed! But the popup is displayed when I use the DocumentumDocumentListGrid  control on other pages!
0
Viktor Tachev
Telerik team
answered on 26 Jun 2014, 11:48 AM
Hi,

Would you try removing the UpdatePanel and disabling Ajax and see if the behavior would change? The Ajax could be disabled by setting the EnableAJAX property of RadAjaxManager to false.

If after Ajax is disabled the controls behave as expected try adding the AjaxSettings on Page_Load like illustrated in this article.

Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
RB
Top achievements
Rank 1
answered on 01 Jul 2014, 05:13 PM
I disabled Ajax and also removed the UpdatePanel. But still no help! Still the RadGrid1_ItemCommand  is not called!
0
Viktor Tachev
Telerik team
answered on 04 Jul 2014, 01:16 PM
Hello,

In order for the ItemCommand to be fired the RadGrid needs to postback. Please ensure that postback is not cancelled.

If it is not and the issue is still observed would you build a small runnable sample that replicates the issue and send it to us in a support ticket. This would allow us to thoroughly investigate the matter and look for the cause of the problem.

Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
RB
Top achievements
Rank 1
answered on 07 Jul 2014, 10:25 PM
Is there a way I can instead add a Delete button in each row and call its onClick event?
0
Princy
Top achievements
Rank 2
answered on 08 Jul 2014, 05:21 AM
Hi,

You can use a GridTemplateColumn to achieve your requirement:

C#:
string deleteColumnName = "Delete";
GridTemplateColumn deleteColumn = new GridTemplateColumn();
deleteColumn.ItemTemplate = new MyDeleteTemplate(deleteColumnName);
deleteColumn.HeaderText = deleteColumnName;
_RadGrid1.MasterTableView.Columns.Add(deleteColumn);
 
public class MyDeleteTemplate : ITemplate
{
    private string colname;
    protected Button btnDelete;
    public MyDeleteTemplate(string cName)
    {
        colname = cName;
    }
    public void InstantiateIn(System.Web.UI.Control container)
    {
        btnDelete = new Button();
        btnDelete.ID = "DeleteColumn";
        btnDelete.Text = "Delete";       
        btnDelete.Click += new EventHandler(btnDelete_Click);
        container.Controls.Add(btnDelete);
    }
    void btnDelete_Click(object sender, EventArgs e)
    {
        //Your code
    }
}

Thanks,
Princy
Tags
Grid
Asked by
RB
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
RB
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or