Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用c#导出到Excel(在webapplication中)_C#_Asp.net_Download_Export To Excel - Fatal编程技术网

使用c#导出到Excel(在webapplication中)

使用c#导出到Excel(在webapplication中),c#,asp.net,download,export-to-excel,C#,Asp.net,Download,Export To Excel,我已经完成了从Gridview到Excel工作表的导出到Excel代码。我有下载对话框。如何通过点击“取消”按钮获取按钮值,无论是保存/下载数据还是关闭对话框 我想在“下载”对话框中确定挂接的按钮是“保存”还是“取消” 代码: 公共void导出(GridView GridView1,DataTable dtGuid) { 您需要提供代码。是否调用返回DialogResult的ShowDialog(),请检查DialogResult.OK string attachment = "

我已经完成了从Gridview到Excel工作表的导出到Excel代码。我有下载对话框。如何通过点击“取消”按钮获取按钮值,无论是保存/下载数据还是关闭对话框

我想在“下载”对话框中确定挂接的按钮是“保存”还是“取消”

代码:

公共void导出(GridView GridView1,DataTable dtGuid) {


您需要提供代码。是否调用返回DialogResult的ShowDialog(),请检查DialogResult.OK
        string attachment = "attachment; filename=ScratchcardDetails.xls";

        Response.ClearContent();

        Response.AddHeader("content-disposition", attachment);

        Response.ContentType = "application/ms-excel";


        StringWriter sw = new StringWriter();

        HtmlTextWriter htw = new HtmlTextWriter(sw);
        GridView1.AllowPaging = false;
        GridView1.Visible = true;
        GridView1.DataSource = dtGuid;
        GridView1.DataBind();


        // Create a form to contain the grid

        HtmlForm frm = new HtmlForm();
        this.GridView1.Parent.Controls.Add(frm);
        frm.Attributes["runat"] = "server";
        frm.Controls.Add(this.GridView1);
        frm.RenderControl(htw);
        //Response.Write(style);
        Response.Write(sw.ToString());
        Response.End();


}
SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == DialogResult.OK)
{
    // Save hit
}