Wednesday, 19 December 2012

Showing CSV/Excel Data in Gridview

Showing CSV/Excel Data in Gridview

Design Part:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head id="Head1" runat="server">

    <title>Auto Complete Example 1</title>



    <form id="form1" runat="server">


        <asp:GridView ID="GridView1" runat="server">







using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;

using System.Configuration;

using System.Web.Services;

using System.Collections;

public partial class Default3 : System.Web.UI.Page


    protected void Page_Load(object sender, EventArgs e)


        System.Data.Odbc.OdbcConnection Conn = null;

        System.Data.DataTable dt = new System.Data.DataTable();

        System.Data.Odbc.OdbcDataAdapter da = null;

        string strConnstr = null;

        string strImportfolder = null;

        string strFilename = null;

        strImportfolder = "E:\\rakesh\\temp\\";

        //strFilename = "test.csv";

        strFilename = "file.csv";

        //this is the csv file to be imported

        strConnstr = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + strImportfolder + ";";

        Conn = new System.Data.Odbc.OdbcConnection(strConnstr);

        da = new System.Data.Odbc.OdbcDataAdapter("select * from [" + strFilename + "]", Conn);


        GridView1.DataSource = dt;




1 comment:

  1. Really a gud website....!!!
    very useful...


Thank You for Your Comments. We will get back to you soon.

back to top