Click here to Skip to main content
Sign Up to vote bad
good
See more: C#ASP.NET
I take one gridview.in that 7 columns..in 7th column i take another gidview.but problem is i want to show this gridview in excel..but in excel it shows only outer grid nag 7 th column is 0..so i want to show 7 column grid also..in 7th column gridview i take three columns and show related data..plz help me
Posted 17 Oct '12 - 0:48


2 solutions

hi
check it out
public void ExportToExcel(DataTable dt)
    {
            con.Open();
            string sql = "select *from test";
            cmd = new SqlCommand(sql, con);
            dt = new DataTable();
            da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            GridView1.DataSource = dt;
            GridView1.DataBind();
            cmd.Dispose();
 

            string filename = "DownloadTest.xls";
            System.IO.StringWriter tw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
            DataGrid dgGrid = new DataGrid();
            dgGrid.DataSource = dt;
            dgGrid.DataBind();
 
            dgGrid.RenderControl(hw);
            
            Response.ContentType = "application/vnd.ms-excel";
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
            this.EnableViewState = false;
            Response.Write(tw.ToString());
            Response.End();
 

            con.Close();
    }
  Permalink  
Hey, check this article, you may find answer here:
9 Solutions to Export Data to Excel for ASP.NET[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 253
1 Rohan Leuva 220
2 Sergey Alexandrovich Kryukov 208
3 Abhinav S 168
4 Mahesh Bailwal 165
0 Sergey Alexandrovich Kryukov 8,494
1 OriginalGriff 6,799
2 CPallini 3,603
3 Rohan Leuva 2,923
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 18 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid