我正在处理我应该将信息导出到csv文件的内容,但是当我尝试在行Response.AddHeader(" content-disposition "attachment; filename = GridViewExport.csv")
我收到错误:
在发送HTTP标头后,服务器无法追加标头。
我的gridview位于og更新面板
内Public Sub archivoGenerado()
For Each RW As GridViewRow In Dgdatoo.Rows
If CType(RW.Cells(10).FindControl("CheckBox2"), CheckBox).Checked = True Then
'If CType(RW.Cells(10).FindControl("Radio"), RadioButton).Checked = True Then
Dim estatus As [String] = CType(RW.Cells(8).FindControl("LabEs"), Label).Text
Dim Centro As [String] = DirectCast(RW.Cells(1).FindControl("LabeCe"), Label).Text
Dim almacen As [String] = DirectCast(RW.Cells(3).FindControl("LabeAl"), Label).Text
Dim Dupla As [String] = DirectCast(RW.Cells(6).FindControl("LabeDu"), Label).Text
Dim constr As New Data.SqlClient.SqlConnection
constr.ConnectionString = C.GetAppConfiguracion("Inventario", "ConnInventario")
Using cmd As New SqlCommand("Select Vw_RptInventarioSAP.IdMaterial as 'Barcode / Item-ID',Vw_RptInventarioSAP.MaterialNombre as'Description',S_AsignacionDuplas.Cantidad as 'Quantity',Vw_RptInventarioSAP.IdLote as 'Lote',S_AsignacionDuplas.IdCentro as 'Centro',S_AsignacionDuplas.IdAlamacen as 'Almacen',S_AsignacionDuplas.IdDupla as 'Dupla' from Vw_RptInventarioSAP inner join S_AsignacionDuplas on Vw_RptInventarioSAP.IdMaterial = S_AsignacionDuplas.IdMaterial where S_AsignacionDuplas.IdDupla = '" & Dupla & "' and IdCentro ='" & Centro & "' and IdAlmacen= '" & almacen & "'")
Using sda As New SqlDataAdapter()
cmd.Connection = constr
sda.SelectCommand = cmd
Dim da As New SqlDataAdapter(cmd)
Using dt As New DataTable()
sda.Fill(dt)
'Build the CSV file data as a Comma separated string.
Dim csv As New StringBuilder()
For i As Integer = 0 To dt.Columns.Count - 1
csv.Append(dt.Columns(i).ColumnName + ",")
Next
csv.Append(Environment.NewLine)
For j As Integer = 0 To dt.Rows.Count - 1
For k As Integer = 0 To dt.Columns.Count - 1
csv.Append(dt.Rows(j)(k).ToString() + ",")
Next
csv.Append(Environment.NewLine)
Next
For Each RW2 As GridViewRow In Dgdatoo.Rows
Response.Clear()
Response.ClearContent()
Response.ContentType = "text/csv"
Response.AddHeader("content-disposition","attachment;filename=GridViewExport.csv")
Response.Write(csv.ToString())
Response.Flush()
Next
'Next
End Using
End Using
End Using
Else
With lbError0
.Visible = True
.Text = "Selecionar inventario a descargar"
End With
End If
Next
End Sub