将数据从Telerik RadGrid导出到Ms-Word

时间:2015-05-26 05:17:23

标签: c# post ms-word telerik export

我试图将Telerik RadGrid导出到Word:

protected void DownloadWord_Click(object sender, EventArgs e)
{
    aGrid.ExportSettings.Word.Format = GridWordExportFormat.Docx;
    aGrid.ExportSettings.ExportOnlyData = true;
    aGrid.ExportSettings.FileName = "test.docx";
    aGrid.MasterTableView.ExportToWord();
    Page.Response.ClearContent();
    Page.Response.ClearHeaders();
}

当我点击按钮时,上面的代码会触发,我会刷新页面。查看POST标题和响应它与加载页面相同,所以它似乎只刷新页面。

出了什么问题?

1 个答案:

答案 0 :(得分:0)

RadGrid将导出的文件写入页面的响应中。由于您正在清除响应及其标题,因此您无法获得文件。

对于您的情况,只需要这个:

protected void ImageButton3_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
  aGrid.ExportSettings.Word.Format = Web.UI.GridWordExportFormat.Docx;              
  aGrid.ExportSettings.FileName = "test.docx";
  aGrid.ExportSettings.ExportOnlyData = true;
  aGrid.MasterTableView.ExportToWord();
}

我无法理解使用:

Page.Response.ClearContent();
Page.Response.ClearHeaders();

除非您为某些特定目的添加了它。

有关使用导出功能的te​​lerik的演示,请参阅here

相关问题