You must Sign In to post a response.
  • Category: .NET

    How to export gridview data to CSV file or Export Gridview data to CSV file using or VB

    How to export gridview data to CSV file or Export Gridview data to CSV file using VB.NET
    AspdotnetRoja
  • #724330
    please check below link :

    http://www.aspdotnet-suresh.com/2011/04/how-to-export-gridview-data-to-csv-file.html

    http://www.dotnetspider.com/forum/327349-How-show-gridview-data-into-csv-using-c.aspx

    http://www.webcodeexpert.com/2013/06/bind-and-export-gridview-data-to-csv.html#.UfZOS9JHJMg

    I Hope To Use Full..
    And Choice The Best Answers

    php-wordpress Developer
    you can any problem to php wordpress to contact me
    jivanibhai7306@gmail.com
    Thanks!!...

  • #724331
    Hi roja,

    Refer below link here they provide both C#.net and VB.net code to export gridview to csv file.

    http://www.aspsnippets.com/Articles/Export-GridView-To-Word-Excel-PDF-CSV-Formats-in-ASP.Net.aspx

    Hope this link will give brief description about exporting data to csv file.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #724359
    Convert this beloe code using a converter from c# to VB.net


    Response.Clear();
    Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
    Response.Charset = "";
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.ContentType = "application/Pandey.xls";

    System.IO.StringWriter stringWrite = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

    myDataGrid.RenderControl(htmlWrite);
    Response.Write(stringWrite.ToString());
    Response.End();

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #724367
    Hi,

    You can try like this below code

    .aspx.cs

    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView><br />
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />


    .aspx.cs

    using System.Data;
    using System.IO;
    public partial class GVExportCSV5 : System.Web.UI.Page
    {
    DataTable dt = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
    dt.Columns.Add("eno");
    dt.Columns.Add("empname");
    dt.Columns.Add("sal");

    dt.Rows.Add("101", "Ravi", "45000");
    dt.Rows.Add("102", "Indran", "15000");
    dt.Rows.Add("103", "Test", "5000");

    GridView1.DataSource = dt;
    GridView1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    StreamWriter sw;
    sw = File.CreateText("D://test123.csv");
    foreach (GridViewRow gr in GridView1.Rows)
    {
    sw.WriteLine(gr.Cells[0].Text + "," + gr.Cells[1].Text + "," + gr.Cells[2].Text );
    }
    sw.Close();

    }
    }

    Regards
    N.Ravindran
    Your Hard work never fails

  • #725173
    you will have to use the Response object to render gridview and export its contents to excel.

    See below article which will tell you how to dynamically export GridView / Repeater data to Excel or PDF

    http://dotnetmentors.com/aspnet/export-gridview-to-excel.aspx

    Laxmikant


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.