2010-08-26 5 views
1

J'ai exporté le code Excel de Gridview vers Excel Sheet. J'ai la boîte de dialogue de téléchargement. Comment obtenir le bouton Valeur si les données sont sauvegardées/téléchargées ou si la boîte de dialogue est fermée en appuyant sur le bouton Annuler ...Exporter vers Excel à l'aide de C# (dans l'application Web)

Je veux identifier le bouton affiché dans Enregistrer ou Annuler dans la boîte de dialogue Télécharger.

code:

public void Export (GridView GridView1, DataTable 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

Vous devez fournir le code. Appelles-tu ShowDialog() qui retourne DialogResult, vérifie DialogResult.OK – Jerome

Répondre

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