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

Export to Excel from usercontrol

3 Answers 179 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Esk
Top achievements
Rank 2
Esk asked on 26 Jun 2008, 07:11 PM
Hello,

I have a grid that has sorting, filtering and export to excel functionality by design. This grid is part of a user control page that is loaded inside of a content asp panel from the parent page. The default.aspx page has the script manager and radajax manager, the later is configured to update the content page when the header or footer are clicked but not it self.

The issue i am having is I cant seem to be able to trigger the export to excel function of the grid. It works fine in a aspx page, but not at all in my usercontrol.
I have read all the posted information and reviewed all available projects regarding working with export in ajax projects. The closest one i saw is exporting from a content page that is loaded by a master page, however that example didn't work either for my practicular environment. 

I tried using Ajax Manager Proxy but no luck so far. Can you please post an example of how to make the export work for a usercontrol scenario in C#? 


Update :  I managed to get it to work somewhat except it only works on the 2nd click of the btnExcel and every click there after.  
This is my code:

Reports.ascx.cs
protected void btnExcel_Click(object sender, EventArgs e)  
        {  
           RadAjaxManager ram = (RadAjaxManager)this.Page.FindControl("ramManager");  
           ram.EnableAJAX = false;  
            gReports.PageSize = gReports.MasterTableView.VirtualItemCount;  
            gReports.ExportSettings.IgnorePaging = true;  
            gReports.ExportSettings.ExportOnlyData = true;  
            gReports.MasterTableView.ExportToExcel();  
        } 

Reports.aspx:
<asp:Button ID="btnExcel" Width="150px" Text="Export to Excel" CommandName="Export" runat="server" OnClick="btnExcel_Click" /> 
 
<telerik:RadGrid ID="gReports" ShowStatusBar="True" Skin="WebBlue" GridLines="None" 
        AllowSorting="True" AllowPaging="True" PageSize="20" Width="100%" runat="server" 
        AllowFilteringByColumn="True" AutoGenerateColumns="False" ItemStyle-Wrap="false" 
        OnItemCommand="gReports_ItemCommand">  
        <MasterTableView TableLayout="Auto" DataKeyNames="service_request_id" CellPadding="3" GridLines="None">  
            <Columns> 
                <telerik:GridTemplateColumn UniqueName="ViewRequestColumn" AllowFiltering="False" HeaderStyle-Width="30px" ItemStyle-Width="30px">  
                    <ItemTemplate> 
                        <asp:LinkButton ID="lbView" runat="server" CommandName="ShowDetails">View</asp:LinkButton> 
                    </ItemTemplate> 
                    <HeaderStyle Width="30px" /> 
                    <ItemStyle Width="30px" /> 
                </telerik:GridTemplateColumn> 
                <telerik:GridBoundColumn HeaderText="Claim Number" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" 
                    DataField="claim_no" UniqueName="claim_no">  
                </telerik:GridBoundColumn> 
            </Columns>            
        </MasterTableView> 
        <ClientSettings> 
            <Selecting AllowRowSelect="True" EnableDragToSelectRows="False" /> 
            <Scrolling AllowScroll="True" ScrollHeight="457px" UseStaticHeaders="True" SaveScrollPosition="True">  
            </Scrolling> 
        </ClientSettings> 
      </telerik:RadGrid> 

Default.aspx:
<telerik:RadScriptManager ID="RadScriptManager" runat="server" /> 
    <telerik:RadAjaxManager ID="ramManager" runat="server" > 
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="pHeader">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="rapCrumb" /> 
                    <telerik:AjaxUpdatedControl ControlID="rapContent" LoadingPanelID="rlpLoading" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
            <telerik:AjaxSetting AjaxControlID="pFooter">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="rapCrumb" /> 
                    <telerik:AjaxUpdatedControl ControlID="rapContent" LoadingPanelID="rlpLoading" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
    <div id="dFrame">  
        <div id="dContent">  
            <asp:Panel ID="rapContent" runat="server">  
            </asp:Panel> 
        </div> 
 As expected after that the sorting, view details and the whole webpage navigation stops working because the ajax remains disabled.
Can you please help me correct that behaviour so it actualy works on the first click and does not affect the rest of the application functionality?


Blagodaria vi mnogo za vremeto vi I se izveniavam za bezpokoistvoto.

3 Answers, 1 is accepted

Sort by
0
Esk
Top achievements
Rank 2
answered on 27 Jun 2008, 01:04 PM
would you be able to help here or do i need to open a support ticket?
0
Accepted
Yavor
Telerik team
answered on 30 Jun 2008, 12:58 PM
Hi Esk,

Basically, in order for the export to work, you should disable the Ajax functionality during the export.
The code supplied does not provide enough information on the structure of the project. It would be best if you open a formal support ticket, and send us a small working project, demonstrating the setup, as well as the issue. We will review it locally, and advise you further.

Sincerely yours,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Esk
Top achievements
Rank 2
answered on 30 Jun 2008, 05:51 PM
Ok I opened a support ticket.

Tags
Grid
Asked by
Esk
Top achievements
Rank 2
Answers by
Esk
Top achievements
Rank 2
Yavor
Telerik team
Share this question
or