RadGrid default filter result export

8 posts, 0 answers
  1. Prasenjit
    Prasenjit avatar
    5 posts
    Member since:
    Nov 2013

    Posted 18 Nov 2013 Link to this post

    hi, i have used radgrid default filter for filtering items in grid using GridBoundColumn. now i want to export the dataset to excel format found by appying filter in columns. how to do it? please let me know.
    sorry for my bad english. 
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Nov 2013 Link to this post

    Hi Prasenjit,

    I guess you want to Export to Excel the RadGrid after applying Filter. Once the RadGrid is filtered, the Grid contains the filtered data, hence this can be directly exported. Please try the following code snippet and let me know if any concern.

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="true">
        <MasterTableView >  
            <Columns>
             . . . . . . . .
            </Columns>
        </MasterTableView
    </telerik:RadGrid>
    <asp:Button ID="ButtonExport" runat="server" Text="ExportToExcel" OnClick="ButtonExport_Click" />

    C#:
    protected void ButtonExport_Click(object sender, EventArgs e)
    {  
        RadGrid1.ExportSettings.ExportOnlyData = true;
        RadGrid1.ExportSettings.IgnorePaging =true;
        RadGrid1.ExportSettings.FileName = "Details";
        RadGrid1.MasterTableView.ExportToExcel();
    }

    Thanks,
    Princy
  3. Prasenjit
    Prasenjit avatar
    5 posts
    Member since:
    Nov 2013

    Posted 18 Nov 2013 Link to this post

    tried this.. it export to .xls format. how can i export to .xlsx format?
  4. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Nov 2013 Link to this post

    Hi Prasenjit,

    Please try setting FileExtension property as shown below:

    C#:
    RadGrid1.ExportSettings.Excel.FileExtension = ".xlsx";

    Thanks,
    Princy
  5. Prasenjit
    Prasenjit avatar
    5 posts
    Member since:
    Nov 2013

    Posted 19 Nov 2013 Link to this post

    it shows error opening the file... please help! 
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Nov 2013 Link to this post

    Hi Prasenjit,

    The warning message you received is seen only with the HTML-based Excel export. There is another Excel export format (in Q2 2012 onwards) which is based on a binary XLS (BIFF) format and is supported in all versions of Microsoft Office, starting from 2003. With it, there is no longer a warning message when you open the exported file. For more information please check this documentation on Biff Export.

    Thanks,
    Princy
  7. Prasenjit
    Prasenjit avatar
    5 posts
    Member since:
    Nov 2013

    Posted 19 Nov 2013 Link to this post

    please tell me the .aspx code and C# code to accomplish the export thing in .xlsx format.
  8. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 20 Nov 2013 Link to this post

    Hi Prasenjit,

    Please try the sample code snippet to Export to Excel.

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1"
        AllowPaging="true" AllowFilteringByColumn="true">
        <MasterTableView DataKeyNames="OrderID">
            <Columns>
                <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" />
                <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" />
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
    <asp:Button ID="ButtonExport" runat="server" Text="ExportToExcel" OnClick="ButtonExport_Click" />

    C#:
    protected void ButtonExport_Click(object sender, EventArgs e)
     {
        RadGrid1.ExportSettings.ExportOnlyData = true;
        RadGrid1.ExportSettings.IgnorePaging = true;
        RadGrid1.ExportSettings.FileName = "Details";
        RadGrid1.ExportSettings.Excel.Format = GridExcelExportFormat.Biff;
        RadGrid1.ExportSettings.Excel.FileExtension = ".xlsx";
        RadGrid1.MasterTableView.ExportToExcel();
     }

    Thanks,
    Princy
Back to Top