Does any one know how to provide file name
to the exported file in Telerik RadGrid
,
Exported file could be of any format pdf, excel or word
Telerik Radgrid export file name
Asked Answered
Source: Grid / MS Excel/MS Word/CSV
Use RadGrid.ExportSettings.FileName property, a string specifying the name (without the extension) of the file that will be created. The file extension is automatically added based on the method that is used Try setting the
FileName
in theItemCommand
event as shown below.
From: When to set RadGrid.ExportSettings.FileName
protected void Radgrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.ExportToPdfCommandName)
{
Radgrid1.ExportSettings.FileName = "yourfilename";
}
if (e.CommandName == RadGrid.ExportToExcelCommandName)
{
Radgrid1.ExportSettings.FileName = "yourfilename";
}
if (e.CommandName == RadGrid.ExportToWordCommandName)
{
Radgrid1.ExportSettings.FileName = "yourfilename";
}
}
Reference:
Export RadGrid content to Excel/Word/CSV/PDF with Ajax enabled
Has anybody gotten the filename property to work correctly? It is getting ignoredby the RadGrid export when I attempt to set it. –
Rhpositive
yes me too... tried several events but it's always ignored –
Plan
You can set the filename as well as other options for exporting, on the ExportSettings
property of the grid (not the MasterTableView
). So for example:
myGrid.ExportSettings.FileName = "file";
myGrid.ExportSettings.Excel.Extension = "xls";
myGrid.MasterTableView.ExportToExcel();
According to the docs you should leave out the extension - "a string specifying the name (without the extension)" demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/… –
Kappel
@Kevin Main I forgot that was the case indeed. Although I do think that the export function will ignore the extension if you leave it in. But I'm not able to test it now, so I'll edit it. Thanks! –
Deprecatory
try
{
object districtid = Session["DistID"];
RadGrid tempGrid = rgDupEmpoyees;
string fileName = "LEA_" + districtid .ToString() + "_PossibleNoShowTonySopranoEmployees_" + DateTime.Now.ToString("dd_MMM_yyyy");
tempGrid.ExportSettings.FileName = fileName;
tempGrid.ClientSettings.Scrolling.UseStaticHeaders = false;
tempGrid.MasterTableView.ExportToPdf();
}
catch (Exception ex)
{
this.LogException(ex);
DisplayPageMessage(ex.GetBaseException().Message, PageMessageType.Error);
//e.Cancel = true;
}
finally
{
this.LogMethodExit();
}
© 2022 - 2024 — McMap. All rights reserved.