2010-08-26 59 views
1

我已经完成了从Gridview到Excel表格导出到Excel代码。我有下载对话框。如何获取按钮值数据是否保存/下载或通过点击取消按钮关闭对话框.....使用c#导出到Excel(在web应用程序中)

我想识别按钮是保存或取消在下载对话框中。

代码:

公共无效出口(GridView控件GridView1,数据表dtGuid) {

 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(); 


} 
+1

您需要提供代码。你是否调用返回DialogResult的ShowDialog(),检查DialogResult.OK – Jerome 2010-08-26 11:17:30

回答

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