Exporting asp.net treeview data control


/ Published in: ASP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. *Note:Please add this property on the page directive otherwise it will generate event Raise Exception "EnableEventValidation="false"" .
  2.  
  3. *Simply call this methood on the event post back your tree will be export to EXCEL,
  4.  
  5.  
  6. private void ExportData()
  7. {
  8.  
  9.  
  10. //// Let's hide all unwanted stuffing
  11. //this.gdvList.AllowPaging = false;
  12. //this.gdvList.AllowSorting = false;
  13. //this.gdvList.EditIndex = -1;
  14.  
  15. // Let's bind data to GridView
  16. // this.BindList();
  17.  
  18. // Let's output HTML of GridView
  19. Response.Clear();
  20. Response.ContentType = "application/vnd.xls";
  21. Response.AddHeader("content-disposition",
  22. "attachment;filename=contacts.xls");
  23.  
  24. StringWriter swriter = new StringWriter();
  25. HtmlTextWriter hwriter = new HtmlTextWriter(swriter);
  26. //if you just want data.
  27. this.TreeView1.ShowExpandCollapse = false;
  28.  
  29. HtmlForm frm = new HtmlForm();
  30. this.TreeView1.Parent.Controls.Add(frm);
  31. //frm.Attributes["runat"] = "server";
  32.  
  33.  
  34. frm.Attributes.Add("runat", "server");
  35. frm.Controls.Add(this.TreeView1);
  36. frm.RenderControl(hwriter);
  37.  
  38. Response.Write(swriter.ToString());
  39. Response.End();
  40. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.