WHEN I UPLOAD EXCEL FILE DYNAMICALLY DISPLAY DROPDOWNS IN HEADER OF GRIDVIEW COLUMNS.

Munikumar G

Total Post:9

Points:63
Posted by  Munikumar G
C# 
C#
 1701  View(s)
Ratings:
Rate this:

Hi,

when i upload excel file, dynamically display dropdowns in header of gridview columns.

 

i am using this code

 

//Check file is available in File upload Control

if (FileUpload1.HasFile)

{

//Store file name in the string variable

string filename = FileUpload1.FileName;

//Save file upload file in to server path for temporary

FileUpload1.SaveAs(Server.MapPath(filename));

//Export excel data into Gridview using below method

ExportToGrid(Server.MapPath(filename));

}

}

void ExportToGrid(String path)

{

OleDbConnection MyConnection = null;

DataSet DtSet = null;

OleDbDataAdapter MyCommand = null;

//Connection for MS Excel 2003 .xls format

MyConnection =

new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data Source='" + path + "';Extended Properties=Excel 8.0;");

//Connection for .xslx 2007 format

MyConnection =

new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + path + "';Extended Properties=Excel 12.0;");

//Connection for .xslx 2010 format

//MyConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.14.0;Data Source='" + path + "';Extended Properties=Excel 14.0;");

//Select your Excel file

MyCommand =

new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection);

DtSet =

new System.Data.DataSet();

//Bind all excel data in to data set

MyCommand.Fill(DtSet,

"[Sheet1$]");

dt = DtSet.Tables[0];

MyConnection.Close();

//Check datatable have records

           

if (dt.Rows.Count > 0)

{

GridView1.DataSource = dt;

GridView1.DataBind();

}

//Delete temporary Excel file from the Server path

if (System.IO.File.Exists(path))

{

System.IO.

File.Delete(path);

}

use munlti headers also......... sort out ASAP.

Thanks

Munikumar

  1. Arun Singh

    Post:68

    Points:476
    Re: when i upload excel file dynamically display dropdowns in header of gridview columns.

    Hi Munikumar,

    Please! Explain your question clearly; what are you trying to ask? Check out following helpful link...

    http://www.mindstick.com/Blog/294/How%20to%20import%20or%20export%20SQL%20Server%20table%20data%20in%20MS%20Excel%20sheet%20using%20C%20Code

    http://www.mindstick.com/Forum/373/How%20to%20import%20data%20from%20excel%20to%20datatable%20in%20c  

    I hope it might be resolve your problem.




Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!