/ Published in: ASP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
*Note:Please add this property on the page directive otherwise it will generate event Raise Exception "EnableEventValidation="false"" . *Simply call this methood on the event post back your tree will be export to EXCEL, private void ExportData() { //// Let's hide all unwanted stuffing //this.gdvList.AllowPaging = false; //this.gdvList.AllowSorting = false; //this.gdvList.EditIndex = -1; // Let's bind data to GridView // this.BindList(); // Let's output HTML of GridView Response.Clear(); Response.ContentType = "application/vnd.xls"; Response.AddHeader("content-disposition", "attachment;filename=contacts.xls"); StringWriter swriter = new StringWriter(); HtmlTextWriter hwriter = new HtmlTextWriter(swriter); //if you just want data. this.TreeView1.ShowExpandCollapse = false; HtmlForm frm = new HtmlForm(); this.TreeView1.Parent.Controls.Add(frm); //frm.Attributes["runat"] = "server"; frm.Attributes.Add("runat", "server"); frm.Controls.Add(this.TreeView1); frm.RenderControl(hwriter); Response.Write(swriter.ToString()); Response.End(); }