Need to Export Gridview1 box to Excel

Skydiver

Well-known member
Joined
Apr 6, 2019
Messages
365
Location
Virginia Beach, VA
Programming Experience
10+
Anyway, why iterate over the rows and columns of the DataGrid? You should be iterating over the rows and columns of the data that you are feeding into the grid.
 

giasone777

Member
Joined
Jul 19, 2019
Messages
21
Programming Experience
1-3
I guess if the gridview is null after being populated isn't it pointless trying to pull data from it.
 

giasone777

Member
Joined
Jul 19, 2019
Messages
21
Programming Experience
1-3
I found the code below to export a gridview to an excel file and it works but the grid lines do not show up in the spreadsheet. I have tried all kinds of variations of different code with no luck. If anyone has any ideas please feel free to share. Thank-you.

C#:
             Response.Clear();
             Response.Buffer = true;
             Response.Charset = "";
             Response.ContentType = "application / vnd.openxmlformats - officedocument.spreadsheetml.sheet";
             Response.AddHeader("content-disposition", "attachment;filename=SqlExport.xls");
             System.IO.StringWriter stringWrite = new System.IO.StringWriter();
             System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
             GridView1.RenderControl(htmlWrite);
             Response.Write("<Gridlines=both>");
             GridView1.GridLines = GridLines.Both;
             GridView1.DataBind();
             GridView1.RenderControl(htmlWrite);
             Response.Write(stringWrite.ToString());
             Response.Write("</table>");
             Response.End();
 

giasone777

Member
Joined
Jul 19, 2019
Messages
21
Programming Experience
1-3
Never mind I figured it out - It was the theme I was using on the gridview.
 
Top Bottom