我在更新面板中有一个gridview。我可以使用HTTP响应将其导出到excel,然后导出所需的数据并在弹出窗口中打开文件,这一切都正常。
但是,一旦导出数据,我必须更新网格视图,表明这些数据已导出。我验证了正确的数据设置为数据源并调用了数据绑定。但是excel导出不会触发屏幕刷新。
如果我通过更改下拉菜单或其他内容来触发刷新,我可以看到数据已更改。我尝试过UpdatePanelID.Update() - 仍然徒劳无功。
那么如何在excel导出后触发gridview刷新?
提前致谢。
我的导出代码:
var excelXml = GetExcelXml(dsInput, filename);
response.Clear();
response.AppendHeader("Content-Type", "application/vnd.ms-excel");
response.AppendHeader("Content-disposition", "attachment; filename=" + filename);
response.Write(excelXml);
response.Flush();
protected void btnExport_Click(object sender, EventArgs e)
{
try
{
if (list.Count() > 0)
{
ds.Tables.Add(dtForExport);
ExcelHelper.ToExcel(ds, filename); //To Excel method is described above.
LoadGridDetails();//Binds the new values
}
}
catch (Exception ex)
{
lblStatus.Text = "Error Exporting to Excel";
}
}//Screen is not refreshed after executing this line.
答案 0 :(得分:1)
你称之为“弹出窗口”,在我看来,你在谈论浏览器下载弹出窗口。 所以,在这种情况下,它不会工作,因为你已经做了一个Response.Clear,你不能再刷新你的网格了。
我的建议是:你可以打开一个真正的弹出窗口,意思是:window.popup,这个弹出窗口会做所有的响应工作,或者你也可以在你的按钮“export”中放一些java脚本做两件事:执行post-back to export功能并等待X毫秒来调用一些隐藏按钮,只是为了进行第二次回复并进行刷新。
希望有所帮助