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

Export Multiple grids to Excel

1 Answer 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Senthil ramna
Top achievements
Rank 1
Senthil ramna asked on 16 Jul 2010, 06:17 AM

This is how my source page looks like

<telerik:RadGrid ID="radGridWrapper" runat="server" ShowHeader="false" BorderStyle="None" Width="100%" 
                       onexcelmlexportstylescreated="radGridWrapper_ExcelMLExportStylesCreated" onexcelmlexportrowcreated="radGridWrapper_ExcelMLExportRowCreated" >
                      <MasterTableView Width="100%">
                            <ItemTemplate>
                                <div id="id1" runat="server" style="width:800px;text-align:left; overflow:hidden;">
                                     <telerik:RadGrid ID="RadGrid1" Width="100%" GridLines="Vertical" 
                                            AllowPaging="true" PageSize="100" 
                                            runat="server" AllowSorting="True" BackColor="white"  Skin="Web20" onitemdatabound="RadGrid1_ItemDataBound"
                                            HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="true"  
                                            HeaderStyle-Font-Names="Arial" onexcelmlexportstylescreated="RadGrid1_ExcelMLExportStylesCreated"
                                            HeaderStyle-Wrap="true" onneeddatasource="RadGrid1_NeedDataSource"   
                                            OnItemCreated="RadGrid1_ItemCreated" OnSortCommand="RadGrid1_SortCommand" 
                                            OnInsertCommand="RadGrid1_InsertCommand"
                                            ongridexporting="RadGrid1_GridExporting"                    
                                            onpdfexporting="RadGrid1_PdfExporting" 
                                            onpageindexchanged="RadGrid1_PageIndexChanged">
                                                <PagerStyle Mode="NumericPages" />
                                                <ClientSettings >
                                                    <Scrolling UseStaticHeaders="true" AllowScroll="true"/>
                                                </ClientSettings>
                                                <ItemStyle Font-Names="Arial" HorizontalAlign="Left" BackColor="white"></ItemStyle>
                                                <AlternatingItemStyle Font-Names="Arial" HorizontalAlign="Left" BackColor="white"/>
                                                <MasterTableView Width="100%">
                                                </MasterTableView>                                        
                                     </telerik:RadGrid>  
                                </div>                                        
                </td>               
                <%--  </div>--%>
                <tr>
                <td style="height: 72px">
                    <telerik:RadGrid ID="RadGrid2" Width="100%" GridLines="Vertical"   Visible="false"
                         runat="server" AllowSorting="True"  Skin="Web20" AllowPaging="true" PageSize="100"
                          HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="true" OnSortCommand="RadGrid2_SortCommand"  
                        HeaderStyle-Font-Names="Arial" onneeddatasource="RadGrid2_NeedDataSource"
                         HeaderStyle-Wrap="true" onpageindexchanged="RadGrid2_PageIndexChanged">
                         <PagerStyle Mode="NumericPages" />
                        <ItemStyle Font-Names="Arial" HorizontalAlign="Left"></ItemStyle>
                        <AlternatingItemStyle Font-Names="Arial" HorizontalAlign="Left" />
                         <MasterTableView Width="100%">                         
                         </MasterTableView>                                        
                    </telerik:RadGrid
                      
                    <br />
                </td>
                </tr>
             <%--  </div>--%>
                            </ItemTemplate>
                       </MasterTableView>
              </telerik:RadGrid>
Everthing works fine, i am able to export both the grids into a single excel.
but i had a question in this i have set page size as 100 as you can see so when i am exporting to excel only the 100 items are getting exported (which is right).
this is my code behind method for exporting
RadGrid radGrid = lbl_txt.Text == "All RadGrids" ? radGridWrapper : (RadGrid)radGridWrapper.Items[0].FindControl(lbl_txt.Text);
          
        //html.Visible = false;
        if (radGrid.Items.Count == 0)
        {
            Page.ClientScript.RegisterStartupScript(base.GetType(), "Alert", GC.Message("No records found"));
            return;
        }
        if (isExcelExport = true)
        {
            gridcaption = "<b style='color: blue; text-align: left;'>Effort Analysis Report </b>";
            if (CheckBox4.Checked == true)
            {
                gridcaption += "<BR/>" + "<b>Process : </b>" + ddlprocess.SelectedItem.Text + " " + "|" + " " + "<b>Group : </b> " + ddlGroupby.SelectedItem.Text + " " + "|" + " " + "<b>From Date :</b>" + txtFromDate.Text + " " + "|" + " " + "<b>To Date :</b>" + txtToDate.Text;
            }
            radGrid.MasterTableView.Caption = gridcaption;
            radGrid.ExportSettings.FileName = "EffortAnalysis_" + "_from_" + txtFromDate.Text + "_to_" + txtToDate.Text;
            radGrid.ExportSettings.OpenInNewWindow = true;
            //radGrid.ExportSettings.IgnorePaging = true;
            //radGrid.ExportSettings.ExportOnlyData = true;
            gridBind();
            radGrid.MasterTableView.ExportToExcel();

so if in this method i add in export settings as ignore paging i am getting an error saying the below message
Object reference not set to an instance of an object.

can any of you guys tell me how i can get over this speed bump

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 21 Jul 2010, 02:28 PM
Hi Senthil,

Try disabling the paging for the grids you want to export. For that purpose you need to set the AllowPaging property to false for the inner grids. You might also need to rebind them.

Let me know if it works.

Regards,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Senthil ramna
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or