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

Error in RadGrid Export to Excel

1 Answer 105 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Yvette
Top achievements
Rank 1
Yvette asked on 22 Dec 2010, 12:12 PM
I have a Radgrid that uses an objectdatasource which is configured this way
<asp:ObjectDataSource runat="server" ID="reportObjectDataSource" SelectMethod="GetInfo"
    EnableViewState="false" TypeName="XXXX.ReportObjectDataSource" 
       onselecting="reportObjectDataSource_Selecting">
       <SelectParameters>
           <asp:FormParameter DbType="DateTimeOffset" 
               DefaultValue="" FormField="timeFrom" Name="frDate" />
           <asp:FormParameter DbType="DateTimeOffset" 
               DefaultValue="" FormField="timeTo" Name="tDate" />
               <asp:FormParameter DbType="Boolean"
               DefaultValue="" FormField="btnAllVer" Name="allVer" />
       </SelectParameters>
   </asp:ObjectDataSource>

The Radgrid is declared in the designer of the page with this code:
<telerik:RadGrid ID="gridReport" runat="server" GridLines="None"
                        Skin="WebBlue" Width="700px"  HeaderStyle-HorizontalAlign="Center" 
                            AllowSorting="True" AllowPaging="true" PageSize="50">
                        <MasterTableView AutoGenerateColumns="True">
                           <CommandItemSettings ShowExportToExcelButton="true"></CommandItemSettings>
  
                        </MasterTableView>
                        <ClientSettings>
                        <Scrolling AllowScroll="true" SaveScrollPosition="true" UseStaticHeaders="true" />
                        </ClientSettings>
                    </telerik:RadGrid>

I also added a button that will be used to export the datagrid once it is clicked. However, after generation of grid and clicking the export button the error: "RadGrid must be DataBound before exporting" is encountered. Here's the code behind for the page:

protected void btnGenerate_Click(object sender, EventArgs e)
        {
 gridReport.DataSourceID = "reportAdhocObjectDataSource";
}
 protected void btnExport_Click(object sender, EventArgs e)
        {
              
            gridReport.ExportSettings.FileName = "Report as of" + DateTime.Today.ToString();
            gridReport.ExportSettings.ExportOnlyData = false;
            gridReport.ExportSettings.IgnorePaging = true;
            gridReport.ExportSettings.OpenInNewWindow = true;
  
            gridReport.MasterTableView.ExportToExcel();
  
        }
  
protected void reportObjectDataSource_Selecting(object sender, System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs e)
        {
            DateTime timeFr = timeFrom.SelectedDate.Value;
            DateTimeOffset tFrom = timeFr;
            e.InputParameters["frDate"] = tFrom;
  
            DateTime timeT = timeTo.SelectedDate.Value;
            DateTimeOffset tTo = timeT;
            e.InputParameters["tDate"] = tTo;
  
            e.InputParameters["allVer"] = this.btnAllVer.Checked;
        }

This is urgent, so please, any help will be appreciated.

thanks

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 27 Dec 2010, 01:46 PM
Hello Yvette,

Unfortunately I'm unable to recreate your scenario on my end. Could you please try to assign the datasource directly in the declaration of the control? You can also try to disable the IgnorePaging property.
Let me know what your findings are.

Regards,
Daniel
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
General Discussions
Asked by
Yvette
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or