Hi friend,
I have some sql data to display in grid view in button click.
|
S.No |
Enquiry_id |
Amount_paid |
Payment_mode |
sl_no |
|
1 |
1 |
1000.0000 |
Check |
1 |
|
2 |
2 |
500.0000 |
Check |
2 |
|
3 |
5 |
1500.0000 |
Check |
3 |
|
4 |
3 |
1500.0000 |
Check |
1 |
|
5 |
4 |
1000.0000 |
Cash |
2 |
I want to export grid view data to excel.
In that grid view remove few column in excel sheet. Using c# code to remove grid view column
Out put
|
S.No |
Amount_paid |
sl_no |
|
1 |
1000.0000 |
1 |
|
2 |
500.0000 |
2 |
|
3 |
1500.0000 |
3 |
|
4 |
1500.0000 |
1 |
|
5 |
1000.0000 |
2 |
foreach (GridViewRow drv in GridView1.Rows)
{
GridViewRow Temporaryheader = GridView1.HeaderRow;
GridViewRow Temporaryfooter = GridView1.FooterRow;
Temporaryheader.Cells[1].Visible = false;
Temporaryfooter.Cells[1].Visible = false;
drv.Cells[1].Visible = false;
Temporaryheader.Cells[3].Visible = false;
Temporaryfooter.Cells[3].Visible = false;
drv.Cells[3].Visible = false;
//---------
drv.Cells[1].Width = Unit.Pixel(1);
drv.Cells[3].Width = Unit.Pixel(5);
drv.Cells[3].Height = Unit.Pixel(10);
}
Export Excel:
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Salary_Details.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
If I export grid view data to excel, the excel sheet cell width not changed but changed in grid view not export to excel formatting width.
Please anyone help me immediately.
Thanks in Advance.

Sanjay KumarRank #561 · 4.3K reputationPosted Nov 5, 2013, 5:47 AM EST
http://www.webcodeexpert.com/2013/06/how-to-bind-and-export-gridview-data-to_21.html
http://www.webcodeexpert.com/2013/06/bind-and-export-gridview-data-to-csv.html#.UnkR0VMw8eM
http://www.c-sharpcorner.com/uploadfile/hrojasara/export-gridview-data-in-csv-format/
sharmila k57 reputationPosted Nov 5, 2013, 8:47 PM EST
Thanks your reply.
I want export gridview data to excel work correctly but i want to change width and height in grdiview column to excel.
Please anyone help me immediatly.
Jonathan Sterling19 reputationPosted Jun 30, 2015, 1:35 AM EDT
RakeshRank #397 · 6.3K reputationPosted Jun 30, 2015, 1:54 AM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 30, 2015, 3:09 AM EDT