TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ajay raju
NA
398
0
convert datagrid data to csv file?
Aug 17 2010 8:15 AM
hi,
first i bind a data into datagrid, this data is displayed in .csv file how to do this? i am try but if long text is displayed in datagrid that time in csv file it take 2 or 3 lines but my aim is if user enter long text that time also it display in single line.
and if i open this csv file in wordpad that time it display comma to last column also. my aim is comma is not displayed for last column.
my code:
Private
Function
ToCSV(
ByVal
dataTable
As
DataTable)
As
String
Dim
sb
As
New
StringBuilder()
If
dataTable.Columns.Count <> 0
Then
For
Each
column
As
DataColumn
In
dataTable.Columns
sb.Append(
","
& column.ColumnName)
Next
sb.Remove(0, 1)
sb.Append(vbCr & vbLf)
For
Each
row
As
DataRow
In
dataTable.Rows
For
Each
column
As
DataColumn
In
dataTable.Columns
sb.Append(row(column).ToString() +
","c
)
Next
sb.Append(vbCrLf)
Next
End
If
Return
sb.ToString()
End
Function
and in button click
'// here i bind datagrid
and then
Response.ContentType =
"Application/x-msexcel"
Response.AddHeader(
"content-disposition"
,
"attachment;filename=Reports.csv"
)
Response.Write(ToCSV(tdata))
Response.[End]()
please help me
Thanks.
Reply
Answers (
1
)
Developing smart Device Application
how to Save Timepan in sqlserver 2008 using Asp.net 3.5