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

Expand/Collapse stopped working

1 Answer 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 07 Aug 2012, 07:22 PM
I could use some clues to help me find what I've done wrong.  Here's the situation:

I have a RadGrid control where there is a top level for Issues where each Issue can have 0-n Action Items.  The grid initially displays just the Issues. Clicking on the expand button causes an Ajax postaback, the Action Items for the selected issue are retrieved and displayed.

This was working fine until I started working on some modifications to make it work in different environment. The change involves getting the name of a SharePoint sub-site from a web part connector instead of assuming the current site. The connector event fires relatively late in lifecycle of a page, so I had to re-arrange data binding code.  I'm sure this has something to do with my problem.

After these changes, the grid no longer expands/contracts when the button is pressed.  The Ajax postback is still occurring and the events are still firing on code behind as expected.  The data is retrieved and added to the child view.  If I expand all the rows declaratively, I can see all the data. The properties of the grid item show "Expanded=true."

Has anybody seen this?  Is there some secret to getting the grid to redraw itself on an Ajax postback when the server side code has rebound data?

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI, Version=2010.3.1317.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="IssuesAndActionsDisplayUserControl.ascx.cs"
    Inherits="DEP.PMIS.Project.Dashboard.IssuesAndActionsDisplay.IssuesAndActionsDisplayUserControl" %>
<Telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default">
    <asp:Label ID="lblLoading" runat="server">Loading... </asp:Label>
</Telerik:RadAjaxLoadingPanel>
<!--Added to hide Recently modified Quick launch -->
<style type="text/css">
.s4-recentchanges
{display:none ;}
</style>
<div class="events-info">
    <Telerik:RadAjaxManagerProxy ID="AjaxManagerProxy1" runat="server">
        <AjaxSettings>
            <Telerik:AjaxSetting AjaxControlID="RadGrid1" >
                <UpdatedControls>
                    <Telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                </UpdatedControls>
            </Telerik:AjaxSetting>
        </AjaxSettings>
    </Telerik:RadAjaxManagerProxy>
    <Telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
        <Telerik:RadGrid ID="RadGrid1" 
            runat="server" 
            OnPreRender="RadGrid1_PreRender" 
            onitemdatabound="RadGrid1_ItemDataBound" 
            OnDetailTableDataBind="RadGrid1_DetailTableDataBind"
            GridLines="None" 
            DataMember="Issues"
            AllowFilteringByColumn="True" 
            AllowSorting="True"
            AllowPaging="True" 
            AutoGenerateColumns="False" 
            onpdfexporting="RadGrid1_PdfExporting"
            onitemcommand="RadGrid1_ItemCommand">
            <ExportSettings IgnorePaging="true" OpenInNewWindow="true" FileName="Issues_And_Actions" >
                <Pdf Title="Issues and Actions Report" PageHeight="13in" PageWidth="19in" />
            </ExportSettings>
            <MasterTableView DataKeyNames="Issue ID" 
                HierarchyDefaultExpanded="true"
                GridLines="None" 
                BorderStyle="Outset" 
                NoMasterRecordsText="No Issues to display" 
                NoDetailRecordsText="No Action Items to display">
                <CommandItemSettings ExportToPdfText="Export to Pdf" />
                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                </RowIndicatorColumn>
                <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" 
                    Visible="True">
                </ExpandCollapseColumn>
                <Columns>
                    <Telerik:GridHyperLinkColumn AllowFiltering="False" 
                        FilterControlAltText="Issue Filter Column" HeaderText="Issue ID" 
                        Text="Link" UniqueName="Issue ID"  ItemStyle-Width="15%" 
                        CurrentFilterFunction="StartsWith" FilterDelay="4000" ShowFilterIcon="false" 
                        ItemStyle-BorderStyle="Outset" ItemStyle-BorderWidth="1px">
                        <ItemStyle Width="15%"/>
                    </Telerik:GridHyperLinkColumn>
                    <Telerik:GridBoundColumn HeaderText="Issue Name" DataField="Issue Name" 
                        ItemStyle-Width="15%" 
                        CurrentFilterFunction="StartsWith" FilterDelay="4000" ShowFilterIcon="false" ItemStyle-BorderStyle="Outset" ItemStyle-BorderWidth="1px">
                        <ItemStyle Width="15%" />
                    </Telerik:GridBoundColumn>
                    <Telerik:GridBoundColumn HeaderText="Issue Description" 
                        DataField="Issue Description" ItemStyle-Width="30%" 
                        CurrentFilterFunction="StartsWith" FilterDelay="4000" ShowFilterIcon="false" ItemStyle-BorderStyle="Outset" ItemStyle-BorderWidth="1px">
                        <ItemStyle Width="30%" />
                    </Telerik:GridBoundColumn>
                    <Telerik:GridBoundColumn HeaderText="Priority" DataField="Issue Priority" 
                        ItemStyle-Width="7%" AutoPostBackOnFilter="true"
                        CurrentFilterFunction="StartsWith" FilterDelay="4000" ShowFilterIcon="false" ItemStyle-BorderStyle="Outset" ItemStyle-BorderWidth="1px">
                        <ItemStyle Width="7%" />
                    </Telerik:GridBoundColumn>
                    <Telerik:GridBoundColumn HeaderText="Created" DataField="Issue Created Date" 
                        ItemStyle-Width="8%" AutoPostBackOnFilter="true" DataFormatString="{0:d}"
                        CurrentFilterFunction="StartsWith" FilterDelay="4000" ShowFilterIcon="false" ItemStyle-BorderStyle="Outset" ItemStyle-BorderWidth="1px">
                        <ItemStyle Width="8%" />
                    </Telerik:GridBoundColumn>
                    <Telerik:GridBoundColumn HeaderText="Completed" 
                        DataField="Issue Completed Date" ItemStyle-Width="8%" DataFormatString="{0:d}"
                        CurrentFilterFunction="StartsWith" FilterDelay="4000" ShowFilterIcon="false" ItemStyle-BorderStyle="Outset" ItemStyle-BorderWidth="1px">
                        <ItemStyle Width="8%" />
                    </Telerik:GridBoundColumn>
                    <Telerik:GridBoundColumn HeaderText="Due Date" 
                        DataField="Target Resolution Date" ItemStyle-Width="8%" DataFormatString="{0:d}"
                        CurrentFilterFunction="StartsWith" FilterDelay="4000" ShowFilterIcon="false" ItemStyle-BorderStyle="Outset" ItemStyle-BorderWidth="1px">
                        <ItemStyle Width="8%" />
                    </Telerik:GridBoundColumn>
                    <Telerik:GridBoundColumn HeaderText="Request Status"  
                        DataField="Request Status" ItemStyle-Width="9%"
                        CurrentFilterFunction="StartsWith" FilterDelay="4000" ShowFilterIcon="false" ItemStyle-BorderStyle="Outset" ItemStyle-BorderWidth="1px">
                        <ItemStyle Width="9%" />
                    </Telerik:GridBoundColumn>
                </Columns>
                <DetailTables>
                    <Telerik:GridTableView runat="server" 
                        DataKeyNames="Issue ID" 
                        DataMember="Actions" 
                        Name="Actions" 
                        GridLines="Horizontal"
                        PageSize="5" 
                        Width="100%" 
                        AllowFilteringByColumn="false" 
                        NoDetailRecordsText="No Action Items to display" 
                        NoMasterRecordsText="No Issues to display"
                        AllowSorting="true">
                        <CommandItemSettings ExportToPdfText="Export to Pdf" />
                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <EditFormSettings>
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                            </EditColumn>
                        </EditFormSettings>
                        <Columns>
                            <Telerik:GridBoundColumn HeaderText="Suggested Action" 
                                DataField="Suggested Action" ItemStyle-Width="35%" >
                                <ItemStyle Width="35%" />
                            </Telerik:GridBoundColumn>
                            <Telerik:GridBoundColumn HeaderText="Assigned To" 
                                DataField="Assigned To" ItemStyle-Width="8%" >
                                <ItemStyle Width="8%" />
                            </Telerik:GridBoundColumn>
                            <Telerik:GridBoundColumn HeaderText="Action Created Date" 
                                DataField="Action Created Date" ItemStyle-Width="8%" >
                                <ItemStyle Width="8%" />
                            </Telerik:GridBoundColumn>
                            <Telerik:GridBoundColumn HeaderText="Completed Date" DataField="Completed Date" ItemStyle-Width="8%" >
                                <ItemStyle Width="8%" />
                            </Telerik:GridBoundColumn>
                            <Telerik:GridBoundColumn HeaderText="Notes" DataField="Resolution Taken" ItemStyle-Width="35%" >
                                <ItemStyle Width="35%" />
                            </Telerik:GridBoundColumn>
                            <Telerik:GridBoundColumn HeaderText="Request Status" DataField="Request Status" ItemStyle-Width="8%" >
                                <ItemStyle Width="8%" />
                            </Telerik:GridBoundColumn>
                        </Columns>
                    </Telerik:GridTableView>
                </DetailTables>
                <EditFormSettings>
                    <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                    </EditColumn>
                </EditFormSettings>
                <PagerStyle Mode="NumericPages" />
            </MasterTableView>
            <FilterMenu EnableImageSprites="False">
            </FilterMenu>
            <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
            </HeaderContextMenu>
        </Telerik:RadGrid>
    </Telerik:RadAjaxPanel>
</div>
<div id="buttonPanel">
    <asp:Label ID="lblExport" runat="server" Text="Export to PDF: "></asp:Label>
    <asp:ImageButton ID="btnExportPDF" runat="server" AlternateText="Export to PDF" 
        ImageUrl="~/_layouts/images/DEP.PMIS.Project.Dashboard/pdficon_large.png" 
        onclick="btnExportPDF_Click" />
    <br />
</div>
<div id="errorPanel">
    <br />
    <asp:Panel ID="ErrorPanel" runat="server" Visible="true">
        <asp:Label ID="lblerror" runat="server" ForeColor="Red"></asp:Label>
    </asp:Panel>
</div>

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
  
using Microsoft.SharePoint;
using Telerik.Web.UI;
  
using DEP.PMIS.Common;
using DEP.PMIS.Entityframework;
using DEP.PMIS.CPortalWebParts.Code;
  
namespace DEP.PMIS.Project.Dashboard.IssuesAndActionsDisplay
{
    /// <summary>
    /// The issues and actions web part has a Telerik RadGrid with a Master/Detail table arrangment
    /// To get the master/detail the DetailTableDataBind bind event is needed.
    /// (Attempts to use Telerik's automatic capabilities didn't work)
    /// </summary>
    public partial class IssuesAndActionsDisplayUserControl : UserControl
    {
        IssuesAndActions _IssuesAndActions;
        private IProjectID _projectInfo;
  
        private SPWeb _projectWeb;
        private bool _shouldDispose;
  
        /// <summary>
        /// Called by the web part when the selected project changes (CPortal)
        /// </summary>
        public IProjectID ProjectInfo
        {
            set
            {
                _projectInfo = value;
                RadGrid1.Rebind();
            }
        }
  
        protected void Page_Load(object sender, EventArgs e)
        {
            _IssuesAndActions = new IssuesAndActions();
  
            if (!Page.IsPostBack)
            {
                  
            }
        }
  
        protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                // Uncomment to expand the first item by default
                //RadGrid1.MasterTableView.Items[0].Expanded = true;
            }
        }
  
        /// <summary>
        /// Called when the detail table is bound to data. Sets the Actions grid's data
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void RadGrid1_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
        {
            try
            {
                OpenWeb();
                GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
                if (e.DetailTableView.Name == "Actions")
                {
                    string IssueID = dataItem.GetDataKeyValue("Issue ID").ToString();
                    e.DetailTableView.DataSource = _IssuesAndActions.Actions(_projectWeb, IssueID);
                      
                }
            }
            catch (Exception ex)
            {
                lblerror.Text = "Error binding Actions table: " + ex.Message + ": " + ex.StackTrace;
                lblerror.Visible = true;
            }
            finally 
            {
                if (_projectWeb != null && _shouldDispose)
                {
                    _projectWeb.Dispose();
                }
            
        }
  
  
        protected void Page_Init(object sender, EventArgs e)
        {
            RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
        }
  
        protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            lblerror.Text = "";
  
            try
            {
                OpenWeb();
                RadGrid1.DataSource = _IssuesAndActions.IssuesActions(_projectWeb);
  
            }
            catch (Exception ex)
            {
                lblerror.Text = "Error binding Issues data: " + ex.Message + ": " + ex.StackTrace;
                lblerror.Visible = true;
            }
            finally
            {
                if (_projectWeb != null && _shouldDispose)
                {
                    _projectWeb.Dispose();
                }
            }
        }
  
        /// <summary>
        /// Called once for each row in the data grid.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            try
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem item = (GridDataItem)e.Item;
                    if (item.DataItem is DataRowView)
                    {
                        DataRowView view = (DataRowView)item.DataItem;
  
                        // Install the URL for the hyperlink column
                        // (Only do this for the Issues table)
                        if (view.Row.Table.TableName == "Issues")
                        {
                            TableCell cell = ((GridDataItem)e.Item)["Issue ID"];
                            HyperLink link = (HyperLink)cell.Controls[0];
  
                            DataRowView rowView = (DataRowView)e.Item.DataItem;
                            DataRow row = rowView.Row;
                            string url = row["Form URL"].ToString();
                            string issueID = row["Issue ID"].ToString();
  
                            link.NavigateUrl = url;
                            link.Text = issueID;
                        }
                    }
                }
  
            }
            catch (Exception ex)
            {
                lblerror.Text = "Error binding data to Issue row: " + ex.Message + ": " + ex.StackTrace;
                lblerror.Visible = true;
            }
        }
  
        protected void btnExportPDF_Click(object sender, ImageClickEventArgs e)
        {
            RadGrid1.MasterTableView.HierarchyDefaultExpanded = true;
            RadGrid1.ExportSettings.FileName = "Issues and Actions for " + SPContext.Current.Web.Name;
            RadGrid1.MasterTableView.ExportToPdf();
        }
  
        protected void RadGrid1_PdfExporting(object sender, GridPdfExportingArgs e)
        {
  
        }
  
        protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.ExpandCollapseCommandName)
            {
                if (e.Item.Expanded == true)
                    e.Item.Expanded = false;
                else
                    e.Item.Expanded = true;
            }
        }
  
        /// <summary>
        /// Opens the SPWeb where the Issues and Actions are found
        /// This could be the current web or, if the Project Info connecter was set, the 
        /// web will be named there.
        /// </summary>
        /// <remarks>
        /// Note that if we use OpenWeb, we need to dispose of things later on.
        /// </remarks>
        private void OpenWeb()
        {
            // Look for the project ID in the Project Info (could be set if part is used in CPortal)
            if (_projectInfo != null)
            {
                _projectWeb = SPContext.Current.Site.OpenWeb(_projectInfo.Name);
                _shouldDispose = true;
  
            }
            else
            {
                // Otherwise assume current site is a project site
                _projectWeb = SPContext.Current.Web;
                _shouldDispose = false;
            }
        }
    }
}

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 10 Aug 2012, 05:13 AM
Hello Michael,

Your grid set up and code-behind seem all right, however, the ajax setting is not correct. You must remove the RadAjaxPanel as RadAjaxManager is equivalent in essence to it, just gives you the advantage of its ajax settings designer. In the second place, when you have to ajaxify controls within an user control, you should do it as demonstrated in the attached sample. And last but not least, do add the following code to the OnInit event of the web part - that should prevent any potential problems with the exporting of the grid:

Page.ClientScript.RegisterStartupScript(typeof(Web_Part1), this.ID, "_spOriginalFormAction = document.forms[0].action;_spSuppressFormOnSubmitWrapper=true;", true);
if (this.Page.Form != null)
{
    string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
    if (!string.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
    {
        this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
    }
}

Hope it helps.

All the best,
Tsvetoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or