//Write pdf bytes to outputstream
// 在线打开
if (DKFS == "pdf")
{
Response.ContentType = "application/pdf";
}
// 下载
if (DKFS == "octet-stream")
{
Response.AddHeader("Content-Disposition", string.Format("attachment;Filename={0}.pdf", Server.UrlEncode(string.Format("租赁意见书({0})", CZRXM))));
}
通常使用:Response.BinaryWrite(m.ToArray());//m是MemoryStream
记得最后加上
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.End();// 很多文章都没有这一句,但是非常重要,我不加就会在post出来的文件末尾加上当前页面代码...好杯具
情况1:
使用dataSource绑定的时候使用一个页面变量,GridViewFlow_RowDeleting先执行,紧接着SqlDataSourceFlow_Deleting
private int rowIndex;
protected void GridViewFlow_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
rowIndex = e.RowIndex;
}
protected void SqlDataSourceFlow_Deleting(object sender, SqlDataSourceCommandEventArgs e)
{
e.Command.Parameters["v_spfabh"].Value = GridViewFlow.DataKeys[rowIndex]["spfabh"].ToString();
e.Command.Parameters["v_qztz"].Value = GridViewFlow.DataKeys[rowIndex]["qztz"].ToString();
e.Command.Parameters["v_hztz"].Value = GridViewFlow.DataKeys[rowIndex]["hztz"].ToString();
e.Command.Parameters["v_gwbh"].Value = GridViewFlow.DataKeys[rowIndex]["gwbh"].ToString();
e.Command.Parameters["v_gzlx"].Value = GridViewFlow.DataKeys[rowIndex]["gzlx"].ToString();
e.Command.Parameters["v_czr"].Value = sysUser.Name;
}
情况2:使用tableAdapter
protected void GridViewApproval_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
DataSetClass.ApprovalStateDataTable dt = new DataSetClass.ApprovalStateDataTable();
DataSetClassTableAdapters.ApprovalStateTableAdapter ta = new DataSetClassTableAdapters.ApprovalStateTableAdapter();
ta.P_DELCONTRACTSTATE(GridViewApproval.DataKeys[e.RowIndex]["HTZTZ"].ToString(), sysUser.Name);
this.ShowStateList();
}
catch (Exception ex)
{
WebAction.MessageBox(this, "add", ex.Message, null);
}
}
需要注意的:如果没使用datasource进行页面的绑定的话,删除或其他操作后,需要主动进行DataBind()的操作,以便删除后能够刷新显示为删除后的列表数据。