我需要在运行时针对 GridView 中的事件生成 Excel 工作表ItemCommand_click
并传输文件,然后将 GridView 与状态更改重新绑定。
当我们使用 File transfer 重定向响应时,如何更新 GridView?
我需要在运行时针对 GridView 中的事件生成 Excel 工作表ItemCommand_click
并传输文件,然后将 GridView 与状态更改重新绑定。
当我们使用 File transfer 重定向响应时,如何更新 GridView?
我希望对行上的选定索引更改执行非常类似的操作,以将报告服务报告输出为 PDF。我只能使用 response.redirect 来处理文件输出的另一个页面。看起来您的问题确实变成了状态更改后重新绑定网格,如果您执行 response.redirect,则无法触摸您的网格...
看看这段代码。我在encosia.com上找到了它。看起来您可以使用 iFrame 进行输出,然后您可以使用 JavaScript 调用回发页面以重新绑定网格。
<html>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" />
<script language="javascript">
// Get a PageRequestManager reference.
var prm = Sys.WebForms.PageRequestManager.getInstance();
// Hook the _initializeRequest event and add our own handler.
prm.add_initializeRequest(InitializeRequest);
function InitializeRequest(sender, args)
{
// Check to be sure this async postback is actually
// requesting the file download.
if (sender._postBackSettings.sourceElement.id == "DownloadFile")
{
// Create an IFRAME.
var iframe = document.createElement("iframe");
// Get the desired region from the dropdown.
var region = $get("Region").value;
// Point the IFRAME to GenerateFile, with the
// desired region as a querystring argument.
iframe.src = "GenerateFile.aspx?region=" + region;
// This makes the IFRAME invisible to the user.
iframe.style.display = "none";
// Add the IFRAME to the page. This will trigger
// a request to GenerateFile now.
document.body.appendChild(iframe);
}
}
</script>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:DropDownList runat="server" ID="Region">
<asp:ListItem Value="N">North Region</asp:ListItem>
<asp:ListItem Value="W">West Region</asp:ListItem>
<asp:ListItem Value="SE">Southeast Region</asp:ListItem>
</asp:DropDownList>
<asp:Button runat="server" ID="DownloadFile" Text="Generate Report" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
处理下载的页面...
protected void Page_Load(object sender, EventArgs e)
{
string FileResponse;
string Region = Request.QueryString["Region"];
// Code here to fill FileResponse with the
// appropriate data based on the selected Region.
Response.AddHeader("Content-disposition", "attachment; filename=report.csv");
Response.ContentType = "application/octet-stream";
Response.Write(FileResponse);
Response.End();
}