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

RadGridView + RadContextMenu + Export to Excel

3 Answers 115 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Meehir
Top achievements
Rank 1
Meehir asked on 17 May 2011, 03:12 PM

Hi,

We are using Telerik RadGridView controls for my Silverlight application and we need to have export to excel functionality by implementing context menu.  So, when user right clicks the grid, context menu should appear and on clicking on one menu item, it should export the grid data to excel.  We are following MVVM models.

Below is my code snippets:
View:
<Telerik:RadGridView x:Name="Grid1" ...>
  <Telerik:RadContextMenu.ContextMenu>
    <Telerik:ContextMenu Name="Menu1">
      <Telerik:MenuItem Header = "Export to Excel" Command="{Binding ExportCommand}" CommandParameter="{Binding ElementName=Grid1}">
      </Telerik:MenuItem>
    </Telerik:ContextMenu>
  </Telerik:RadContextMenu.ContextMenu
</Telerik:RadGridView>

In ViewModel, I have created the ICommand variable "ExportCommand" as below

public ICommand ExportCommand
{
  get

  {

      _exportCommand = new DelegateCommand<object>(

                commandParameter => {
                         var grid = commandParameter as RadGridView;
                          .... put all the code to show dialog for exporting to excel which is working in other forms perfectly
                          ..... but with CommandButton
                         grid.Export()

                 }

      );
     return _exportCommand;

  }
}

I am not getting the grid to export.  On executing below line, the grid variable becomes null.  So no data to export to excel.
var grid = commandParameter as RadGridView;

Kindly help.

Thanks,
Meehir Jha

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 18 May 2011, 08:12 AM
Hello,

 ElementName binding will not work in this case. I've attached example project to illustrate you how to achieve your goal.

All the best,
Vlad
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
0
Ricardo
Top achievements
Rank 1
answered on 24 Jun 2014, 03:27 PM
Hola, quiero exportar mi RadGridview desde un comando Command="{Binding ComandoExportar}" CommandParameter="{Binding ElementName=gdvILI}" pero al exportarlo sólo me exporta la página actual del Gridview y yo quiero exportar todo el Gridview sin importar el paginado.
0
Dimitrina
Telerik team
answered on 25 Jun 2014, 09:14 AM
Hello,

You can check the "Export FAQ" article in our online documentation on how to achieve your goal.
Basically, you need to:
  • Save the PageSize and the PageIndex of RadDataPager

  • Set the PageSize of RadDataPager to 0

  • Export the data (you can use the (IEnumerable) dataPager.PagedSource as GridViewExportOptions.Items)

  • Set the PageSize and the PageIndex back


You can also export data with RadSpreadProcessing. The model is completely independent from UI. You can check our new example Export with RadSpreadProcessing on how to do so.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Meehir
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Ricardo
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or