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

RadGrid ExcelML Export Error

4 Answers 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mohamed Salah Al-Din
Top achievements
Rank 1
Mohamed Salah Al-Din asked on 29 May 2012, 03:38 PM

i am facing a problem with grid excel export, after clicking export the grid is disappearing and nothing happean

MasterPage:

<telerik:RadScriptManager ID="Main_RadScriptManager" runat="server" />
    <telerik:RadAjaxManager ID="Main_RadAjaxManager" runat="server" >
        <AjaxSettings></AjaxSettings>
        <ClientEvents OnRequestStart="OnRequestStart" />
    </telerik:RadAjaxManager>
    <telerik:RadFormDecorator ID="Main_RadFormDecorator" runat="server" DecoratedControls="All" Skin="Office2007" />
    <telerik:RadStyleSheetManager ID="Main_RadStyleSheetManager" runat="server">
    </telerik:RadStyleSheetManager>
    <telerik:RadCodeBlock ID="Main_RadCodeBlock" runat="server">
        <script type="text/javascript">
            function OnRequestStart(sender, args) {
                if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0) {
                    args.set_enableAjax(false);
                }
            }
        </script>
    </telerik:RadCodeBlock>
     
    <asp:UpdatePanel ID="Master_UpdatePanel" runat="server" UpdateMode="Conditional" >
        <ContentTemplate>
            <asp:ContentPlaceHolder ID="Popup_ContentPlaceHolder" runat="server" >
            </asp:ContentPlaceHolder>
        </ContentTemplate>
    </asp:UpdatePanel>


ContentPage:

<asp:Content ID="Content2" ContentPlaceHolderID="Popup_ContentPlaceHolder" runat="Server">
    <telerik:RadSplitter ID="InnerRadSplitter" runat="server" Height="560px" Width="100%"
        Orientation="Horizontal" ResizeMode="AdjacentPane" ResizeWithParentPane="true"
        Skin="Vista">
        <telerik:RadPane ID="SearchRadPane" runat="server" MaxHeight="150" MinHeight="70"
            Scrolling="Y" Width="100%">
            <div class="panel message info">
                 
            </div>
        </telerik:RadPane>
        <telerik:RadSplitBar ID="SearchRadSplitBar" runat="server">
        </telerik:RadSplitBar>
        <telerik:RadPane ID="ResultRadPane" runat="server" Scrolling="None">
            <telerik:RadGrid ID="grdData" AllowPaging="false" AllowSorting="false" runat="server"
                AutoGenerateColumns="false" Width="100%" Height="100%" Skin="Vista" GridLines="None"
                OnItemCreated="grdData_ItemCreated" OnItemCommand="grdData_ItemCommand">
                <ClientSettings EnableAlternatingItems="true" EnableRowHoverStyle="true">
                    <Selecting AllowRowSelect="true" />
                    <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="true">
                    </Scrolling>
                </ClientSettings>
                <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true">
                    <Excel Format="ExcelML" />
                </ExportSettings>
                <MasterTableView AutoGenerateColumns="false" Width="100%" CommandItemDisplay="Top">
                    <NoRecordsTemplate>
                        <div style="text-align: center; font-weight: bold">
                            NO_INFO_AVLBL</div>
                    </NoRecordsTemplate>
                    <CommandItemTemplate>
                        <telerik:RadToolBar ID="ReportGenerator_ToolBar" runat="server" Width="100%" EnableRoundedCorners="true"
                            EnableShadows="true" Skin="Vista" OnButtonClick="ReportGenerator_ToolBar_ButtonClick">
                            <Items>
                                <telerik:RadToolBarButton Text="Export" Value="Excel_Export"                           CommandName="ExportGrid" >
                                </telerik:RadToolBarButton>
                            </Items>
                        </telerik:RadToolBar>
                    </CommandItemTemplate>
                </MasterTableView>
            </telerik:RadGrid>
        </telerik:RadPane>
        <telerik:RadPane ID="FooterRadPane" runat="server" Height="70" Scrolling="None" Width="100%"
            Locked="true">
            <div class="mainsection buttons-section" style="margin: 5px;">
                <asp:Button ID="btn_ReportGeneratorRun" runat="server" Text="Search"
                    class="button button-blue" OnClick="btn_ReportGeneratorRun_Click" Width="80px" />
            </div>
        </telerik:RadPane>
    </telerik:RadSplitter>
</asp:Content>

ContentPage Code:

protected void grdData_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item.ItemType == GridItemType.CommandItem)
        {
            RadToolBar ReportGenerator_ToolBar = (RadToolBar)e.Item.FindControl("ReportGenerator_ToolBar");
            RadToolBarItem Excel_Export = ReportGenerator_ToolBar.FindItemByValue("Excel_Export");
            RadScriptManager.GetCurrent(this.Page).RegisterPostBackControl(Excel_Export);
        }
    }
 
protected void ReportGenerator_ToolBar_ButtonClick(object sender, RadToolBarEventArgs e)
    {
        string ErrorMessage = "";
        try
        {
            //---------------------------------------
            if (e.Item.Value == "Excel_Export")
            {
                grdData.ExportSettings.FileName = DateTime.Today.ToString("dd.MM.yyyy");
                 
                grdData.ExportSettings.IgnorePaging = true;
                grdData.ExportSettings.OpenInNewWindow = true;
                grdData.MasterTableView.ExportToExcel();
            }
            //---------------------------------------
        }
        catch (Exception ex)
        {
            ErrorMessage += ex.Message;
        }
    }

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 May 2012, 11:50 AM
Hi,

I would suggest that you not mix RadAjaxManager and asp:UpdatePanels. With RadAjaxManager in your MasterPage you can ajaxify and update every single control in your application. I could get the desired functionality on removing UpdatePanel from the MasterPage. Please take look into this help documentation.

Thanks,
Shinu.
0
Mohamed Salah Al-Din
Top achievements
Rank 1
answered on 03 Jun 2012, 07:49 AM
Dear Shinu,

i tried to remove the asp:UpdatePanel from the MasterPage but the result is not right, since now any action on the page will lead to a Postback and the page will blink even for grid paging change or any button click
0
Mohamed Salah Al-Din
Top achievements
Rank 1
answered on 03 Jun 2012, 08:29 AM
i made some changes

1. add RadAjaxManagerProxy to the ContentPage

<telerik:RadAjaxManagerProxy ID="Email_RadAjaxManagerProxy" runat="server" >
</telerik:RadAjaxManagerProxy>

2. In Page_PreRender Event i Added The Following Code:

protected void Page_PreRender(object sender, EventArgs e)
    {
        GridCommandItem Email_Command = (GridCommandItem)Email_RadGrid.MasterTableView.GetItems(GridItemType.CommandItem)[0];
        RadToolBar Email_ToolBar = Email_Command.FindControl("Email_ToolBar") as RadToolBar;
        RadToolBarItem _Export = Email_ToolBar.FindItemByValue("Export");
        ImageButton btn_Export = (ImageButton)_Export.FindControl("btn_Export");
        RadAjaxManager.GetCurrent(this.Page).AjaxSettings.AddAjaxSetting(btn_Export, Email_RadGrid);
}

now Export is working but with one problem that the grid layout is changed please check the attached image.

i think this change in the grid layout is because the AjaxManagerProxy. specially in this line:

RadAjaxManager.GetCurrent(this.Page).AjaxSettings.AddAjaxSetting(btn_Export, Email_RadGrid);




0
Mohamed Salah Al-Din
Top achievements
Rank 1
answered on 04 Jun 2012, 06:22 AM
Thanks Telerik for your reply :(

i solved it myself by adding the following parameters to the code:

RadAjaxManager.GetCurrent(this.Page).AjaxSettings.AddAjaxSetting
	(
	btn_Export, Email_RadGrid,Email_RadAjaxLoadingPanel,
	UpdatePanelRenderMode.Block,Unit.Percentage(100)
	);

Which set the UpdatePanelHeight to 100%
Tags
Grid
Asked by
Mohamed Salah Al-Din
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mohamed Salah Al-Din
Top achievements
Rank 1
Share this question
or