Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi sir,

in my web app i am display Excel data to Datagrid. its working fine.
datagrid cells header text is displayed column names of Excel sheet
data.

but my aim is i want to display other names for my datagrid cells Header Text.

my code is:

String strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Book2.xls;" +
"Extended Properties=Excel 8.0;";
DataSet ds = new DataSet();

OleDbDataAdapter da = new OleDbDataAdapter
("SELECT * FROM [Sheet1$]", strConn); 

da.Fill(ds);
DataGrid2.DataSource = ds.Tables[0].DefaultView;
DataGrid2.DataBind();


please give me a solution

Thanks.
Posted

Add the columns in gridview with the headers u want and while stating select statement mention the headers associated with perticular field with AS clause
(example select student_name as name)
and then bind datasource
 
Share this answer
 
Comments
ajay.raju531 16-Sep-10 8:21am    
Thank you amyjust4u
amyjust4u 16-Sep-10 8:53am    
did it work
You can also use DataGridColumn.HeaderText Property[^] to change the text of the header.

Check the link for more details.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900