converted gridview to csv but no headers

I converted gridview to CSV but the headers on the gridview are not shown on the CSV file.

public void btnToCSV_Click(object sender, EventArgs e)

{     Response.Clear();     Response.Buffer = true;     Response.AddHeader("content-disposition", "attachment;filename=Report.csv");     Response.Charset = "";     Response.ContentType = "application/text";     gvReport.AllowPaging = false;     StringBuilder sBuilder = new System.Text.StringBuilder();     for(int index = 0; index < gvReport.Columns.Count; index++)     {         sBuilder.Append(gvReport.Columns[index].HeaderText + ',');     }     sBuilder.Append("\r\n");     for(int i = 0; i <gvReport.Rows.Count; i++)     {         for(int k = 0; k < gvReport.HeaderRow.Cells.Count; k++)         {             sBuilder.Append(gvReport.Rows[i].Cells[k].Text.Replace(",","") + ",");         }         sBuilder.Append("\r\n");     }     Response.Output.Write(sBuilder.ToString());     Response.Flush();     Response.End(); } 

Replay

Category: c# Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.250 (s). 12 q(s)