Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2696 connectés 

  FORUM HardWare.fr
  Programmation
  ASP

  [C#][ASP.NET1.1]Exporter datagrid vers un fichier excel ou word

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[C#][ASP.NET1.1]Exporter datagrid vers un fichier excel ou word

n°1564973
cervantes
Posté le 25-05-2007 à 08:56:51  profilanswer
 

Bonjour,
 
Voila, je souhaite exporter la datagrid de ma page aspx dans un fichier excel et word. J'ai utilisé cette fonction
 

Code :
  1. private void ExportToWord_Click(object sender, System.EventArgs e)
  2. {
  3. // Get the filename selected by the user  
  4. string wordFilename = Request.QueryString["filename"].ToString();
  5. // Add the doc extension
  6. wordFilename = wordFilename.Replace("xml", "doc" );
  7. Response.Clear();
  8. Response.AddHeader("content-disposition", "attachment;filename=" + wordFilename);
  9. Response.Charset = "";
  10. Response.Cache.SetCacheability(HttpCacheability.NoCache);
  11. Response.ContentType = "application/vnd.word";
  12. System.IO.StringWriter stringWrite = new System.IO.StringWriter();
  13. System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
  14. this.MetadataDataGrid.RenderControl(htmlWrite);
  15. Response.Write(stringWrite.ToString());
  16. Response.End();
  17. }


 
Lorsque j'execute cette fonction, j'ai une erreur:
 

Citation :


Control 'MetadataDataGrid__ctl1__ctl0' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server.  
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.  
 
Exception Details: System.Web.HttpException: Control 'MetadataDataGrid__ctl1__ctl0' of type 'DataGridLinkButton' must be placed inside a form tag with runat=server.


 
J'ai trouve ou provient cette erreur, elle a lieu parce que j'ai l'option AllowSorting="true" d'activer de ma datagrid dans ma page aspx. Quand je la passe a false, ma fonction d'export vers un fichier excel marche niquel.
 
Donc que faire pour pouvoir exporter vers excel ou word tout en conserver l'attribut AllowSorting="true"? (je ne peux malheureusement pas me passer de cette option)
 
Merci d'avance
++

mood
Publicité
Posté le 25-05-2007 à 08:56:51  profilanswer
 

n°1578390
mugenx
Posté le 23-06-2007 à 18:45:07  profilanswer
 

Est ce que tu as vérifié si tu as bien placé ton DataGrid entre des balises "form".
 
'DataGridLinkButton' must be placed inside a form tag with runat=server.  
 
Je pense que ton DataGrid, lorsque l'option AllowSorting est à true, a besoin de passer par le serveur pour charger correctement les données.


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  ASP

  [C#][ASP.NET1.1]Exporter datagrid vers un fichier excel ou word

 

Sujets relatifs
Excel : faire une recherche de valeurs "compris entre" ![RESOLU]Récupération des données d'un fichier .txt
Manipuler un simple fichier texte ?!planning sur excel
transfert de fichier de linux vers windows & vise vers caremplacer un ligne dans un fichier
C# créer DLL et l'utiliser sous Excel[Hibernate]Migration vers 3.1 et "could not instantiate id generator"
MSSQL : Datatype "image" : comment exporter ? 
Plus de sujets relatifs à : [C#][ASP.NET1.1]Exporter datagrid vers un fichier excel ou word


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR