Answered by:
export gridview to csv

Question
-
plz help me how can handle and correct my code.
im using that code its working fine but problem is that.
my database table like that
name address description
jhon rbnr,rrn test,check,d
when we export to csv file the description cloumn and address column show like that in excel
excel sheet.
description column in excel like that divided in 3 column
tes check d
and
address column divided 2 column in excel
DataSet ds = check.GetInstance().GetcheckReport(pocheck);
Response.Clear();
Response.Buffer =true;
Response.AddHeader("content-disposition","attachment;filename=GridViewExport.csv");
Response.Charset ="";
Response.ContentType ="application/text";
DGResult.DataSource = ds.Tables[0];
DGResult.DataBind();
StringBuilder sb =newStringBuilder();
for (int k = 0; k < DGPOResult.Columns.Count; k++)
{
//add separator
sb.Append(DGPOResult.Columns[k].HeaderText +',').Replace(" ",string.Empty);
}
//append new line
sb.Append("\r\n");
for (int i = 0; i < DGPOResult.Rows.Count; i++)
{
for (int k = 0; k < DGPOResult.Columns.Count; k++)
{
//add separator
sb.Append(DGResult.Rows[i].Cells[k].Text +',').Replace(" ",string.Empty);
}
//append new line
sb.Append("\r\n");
}
Response.Output.Write(sb.ToString());
Response.Flush();
Response.End();
plz help ev1
- Moved by Jason Dot Wang Thursday, May 3, 2012 4:58 AM This topic is about ASP.NET (From:Visual C# General)
Wednesday, May 2, 2012 11:19 AM
Answers
-
The problem arises if there is a field that contains the same character used as column separator.
You must enclose each value in quotation marks (") or use a character seprator that is not present in your data, for example ; or \t (TAB).
Marco Minerva [MCPD]
Blog: http://blogs.ugidotnet.org/marcom
Twitter: @marcominerva- Edited by Marco MinervaMVP Wednesday, May 2, 2012 12:52 PM
- Proposed as answer by Jason Dot Wang Thursday, May 3, 2012 4:54 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Thursday, May 10, 2012 8:00 AM
Wednesday, May 2, 2012 12:47 PM -
Hi guy,
You'll need to post it in the dedicated ASP.Net Forum http://forums.asp.net for more efficient responses, where you can contact ASP.NET experts.
Sincerely,
Jason Wang
Jason Wang [MSFT]
MSDN Community Support | Feedback to us
- Marked as answer by Ed Price - MSFTMicrosoft employee Thursday, May 10, 2012 8:00 AM
Thursday, May 3, 2012 4:57 AM
All replies
-
The problem arises if there is a field that contains the same character used as column separator.
You must enclose each value in quotation marks (") or use a character seprator that is not present in your data, for example ; or \t (TAB).
Marco Minerva [MCPD]
Blog: http://blogs.ugidotnet.org/marcom
Twitter: @marcominerva- Edited by Marco MinervaMVP Wednesday, May 2, 2012 12:52 PM
- Proposed as answer by Jason Dot Wang Thursday, May 3, 2012 4:54 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Thursday, May 10, 2012 8:00 AM
Wednesday, May 2, 2012 12:47 PM -
Hi guy,
You'll need to post it in the dedicated ASP.Net Forum http://forums.asp.net for more efficient responses, where you can contact ASP.NET experts.
Sincerely,
Jason Wang
Jason Wang [MSFT]
MSDN Community Support | Feedback to us
- Marked as answer by Ed Price - MSFTMicrosoft employee Thursday, May 10, 2012 8:00 AM
Thursday, May 3, 2012 4:57 AM