Return to Snippet

Revision: 45855
at May 9, 2011 22:58 by kashif21


Initial Code
*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();
        }

Initial URL

                                

Initial Description

                                

Initial Title
Exporting asp.net treeview data control

Initial Tags
data, aspnet

Initial Language
ASP