Here is the sample code for exporting Telerik Gridview in silverlight.
private void btnExportOrders_Click(object sender, RoutedEventArgs e){// Checking whether grid has rowsif (OrderGrid.Items.Count > 0){string extension = "xls";string selectedItem = "Excel";ExportFormat format = ExportFormat.ExcelML;SaveFileDialog dialog = new SaveFileDialog();dialog.DefaultExt = extension;dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, selectedItem);dialog.FilterIndex = 1;if (dialog.ShowDialog() == true){using (Stream stream = dialog.OpenFile()){GridViewExportOptions options = new GridViewExportOptions();options.Format = format;options.ShowColumnHeaders = true;options.Encoding = Encoding.UTF8;options.ShowColumnHeaders = true;// name of the grid which you want exportOrderGrid.Export(stream, options);}}}else{// User friendly MessageMessageBox.Show("There are no records to export.", "Export Warning!", MessageBoxButton.OK);}}
This export code will also support different formats like CSV,Text and HTML. All you need to change is the enum type for ExportFormat to above formats and the extension. Its easy and simple. Good luck
Thanks! its helpfull article.
ReplyDeleteWhat if i dont want to include all the columms into the excel
ReplyDelete