有人知道如何在 Telerik RadGrid 中为导出的文件提供 "文件名" 吗?导出的文件可以是任何格式,如:pdf、excel 或 word。
来源: Grid / MS Excel/MS Word/CSV
使用RadGrid.ExportSettings.FileName属性,该属性是一个字符串,用于指定将创建的文件的名称(不包括扩展名)。根据所使用的方法自动添加文件扩展名。尝试在
ItemCommand
事件中设置FileName
,如下所示。
来自: 何时设置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";
}
}
您可以在网格的ExportSettings
属性(而不是MasterTableView
)上设置文件名以及其他导出选项。例如:
myGrid.ExportSettings.FileName = "file";
myGrid.ExportSettings.Excel.Extension = "xls";
myGrid.MasterTableView.ExportToExcel();
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();
}