I have a reporting page I am working on and I need to get this gridview exported to CSV. I have gotten everything setup properly but now when I export it the key collumn data is empty while all others are there. No where in the code do I mess with this actual data but I do check it to set visibility of the row. Here are the 3 key functions.: also note that this gridview renders perfect with all the data its not until its getting exported that the "Assignment" column gets blanked.
Protected Sub gvWaranaty_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvWaranaty.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then e.Row.Visible = False If Not Request.QueryString("Region") = "" Then Dim y As String = e.Row.DataItem("Assignment") For Each z As String In x 'x is set on_load and populated with all the properties in QueryString(Region) If y = z Then e.Row.Visible = True End If Next End If End If End Sub Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click Response.Clear() Response.AddHeader("content-disposition", "attachment;filename=ExperationReport" + Date.Now + ".csv") Response.Charset = "" Response.ContentType = "application/vnd.xls" Dim htmlwrite As New System.Web.UI.HtmlTextWriter(CSV_EXPORT()) Response.Write(CSV_EXPORT()) Response.End() End Sub Protected Function CSV_EXPORT() As StringWriter Dim sw As StringWriter = New StringWriter() Dim ColCount As Integer = gvWaranaty.Columns.Count For i As Integer = 0 To (ColCount - 1) Step 1 sw.Write(gvWaranaty.Columns(i)) If i < ColCount - 1 Then sw.Write(",") End If Next sw.Write(sw.NewLine) For Each dr As System.Web.UI.WebControls.GridViewRow In gvWaranaty.Rows For i As Integer = 0 To (ColCount - 1) Step 1 If dr.Visible = True Then 'If its not visible dont export it If Not dr.Cells.Item(i).Text = "" Then sw.Write(dr.Cells.Item(i).Text) End If If i < ColCount - 1 Then sw.Write(",") End If End If Next sw.Write(sw.NewLine) Next sw.Close() Return sw End Function
please advise or point to an article that will shed some light on this...I'm baffled but then again it is monday morning :P.
Thanks in advance