Try this, i think its working
you bind your datagrid value into xlDV and you can access code like this,
Dim dt As New DataTable
dt = xlDV.ToTable
'Get the data from database into datatable
Response.Clear()
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment;filename=ExpData.csv")
Response.Charset = ""
Response.ContentType = "application/text"
Dim sb As New StringBuilder()
For k As Integer = 0 To dt.Columns.Count - 1
'add separator
sb.Append(dt.Columns(k).ColumnName + ","c)
Next
'append new line
sb.Append(vbCr & vbLf)
For Each resultDR As DataRow In dt.Rows
For Each resultDC As DataColumn In dt.Columns
Dim strTemp As String = resultDR.Item(resultDC.ColumnName).ToString()
If strTemp.Contains(System.Environment.NewLine) = True Then
strTemp = strTemp.Replace(System.Environment.NewLine, " ")
End If
'add separator
sb.Append(strTemp.Replace(",", ";") + ","c)
Next
'append new line
sb.Append(vbCr & vbLf)
Next
Response.Output.Write(sb.ToString())
Response.Flush()
Response.End()
Thanks,
jeyamothi