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

GridExported?

5 Answers 99 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 15 Oct 2009, 10:22 AM
We have a grid the user wants to use to export data.  Once the export is completed, we want to update a 'last exported date'.

I've tried putting code right after I call grid.MasterTable.ExportToExcel() which will perform this update, but the excel spreadsheet has the 'new' last export date instead of the old one.   I've tried putting code into the OnExcelMLExportRowCreated, but that's not doing what I want either.   we've also looked at the gridExporting event to try and get it to happen after the export actually gets the data from the database - but the ExportToExcel method seems to get data after this occurs as well.

So is there a way I can accomplish this (say a GridExported event) that I am just missing?

5 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 20 Oct 2009, 04:22 PM
Hello Joe,

I am not sure about the algorithm you use to calculate the last exported date in this case, however you can intercept the OnGridExporting event which is fired right before the data is processed to Excel in order to determine the export date and place it as part of the Caption property of the master table to be included in the exported file.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Joe
Top achievements
Rank 1
answered on 20 Oct 2009, 04:52 PM
What we want to do is update the database so other users know when the last export date was so they can filter in a grid (e.g. we want to filter out anything that was exported after October 1).   If I perform the update in the OnGridExporting event (using the FilterExpression to set create a list that matches what is displayed on-screen), the exported data will show the new 'last exported' date instead of the previous
0
Sebastian
Telerik team
answered on 23 Oct 2009, 03:12 PM
Hello Joe,

I am not sure whether I understand your scenario completely. Can you please more detailed description about each step you followed during the export and the results from them? This will help me provide more to-the-point explanation/solution. Thank you.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Joe
Top achievements
Rank 1
answered on 26 Oct 2009, 11:50 AM
The method ExportData is set to be fired for OnGridExporting.   When this fires, we unhide some columns that are only used for export purposes, we call the export method for the MasterTable.   We then create a new DataView with the same data that's currently being displayed in the grid (since we can't access the filtered grid's row items directly) and update the rows in the database to set their ExportDate value to be right now.   The new date we set the ExportDate to, appears in the export.  Instead we were expecting the prior export date.

 

 

    protected void ExportData(object sender, EventArgs e)  
    {  
        foreach (GridColumn _col in gridRequests.MasterTableView.Columns)  
            _col.Display = true;  
          
        switch (((LinkButton)sender).CommandArgument.ToString())  
        {  
            case "PDF":  
                gridRequests.MasterTableView.ExportToPdf();  
                break;  
            case "Excel":  
                gridRequests.ExportSettings.Excel.Format = GridExcelExportFormat.Html;  
                gridRequests.MasterTableView.ExportToExcel();  
                break;  
        }  
 
        Budget.Requests _req = new Budget.Requests();  
        System.Data.DataView _update = _req.GetWingateExport().DefaultView;  
        _update.RowFilter = gridRequests.MasterTableView.FilterExpression;  
 
        foreach (System.Data.DataRow _row in _update.ToTable().Rows)  
        {  
            Budget.Requests.UpdateExportDate(Convert.ToInt32(_row["BudgetRequestID"].ToString()));  
        }  
 
    }
          
          
                 
          
 

 

For example, if I have 2 rows of data in the filtered grid and it's currently October 25, 2009 10:01AM.  The last export date for these 2 rows was  October 15, 2009 9:00AM I would expect the following:

DataID        Name            ExportDate
1                Testing            2009-15-10 9:00
2                Testing 2        2009-15-10 9:00

instead I get
DataID        Name            ExportDate
1                Testing            2009-25-10 10:00
2                Testing 2        2009-25-10 10:00



    

 

0
Sebastian
Telerik team
answered on 29 Oct 2009, 12:35 PM

Hello Joe,

Thank you for the detailed explanation. Now I think I understand what you mean.

Can you please check whether the last exported date in the Excel document is reflected as expected if you invoke the UpdateExportDate method from within the OnPreRenderComplete handler of the page? Since the grid is rebound after the LinkButton click event handler and before the export operation takes place, the update should happen after that in order to keep the last exported date in the exported file.

Kind regards,

Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Joe
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Joe
Top achievements
Rank 1
Share this question
or