As the title describes I am having an issue exporting some data from a grid to CSV. Here is our use case:
We query data from our database, the page examines the data and then displays errors for each cell where the data is improper for the external system that the data will eventually be fed into. After the user fixes the "first stage" errors another two error checking stages are enabled. Once these stages are also passed, the user can then click on a button that hides all of the original rows and displays the rows we have added to the grid for export. At this point all of the data in the database for these records has been fixed.
Once they click on the Prepare Data for Export button, they will then be able to click on the Export Data button. Both of these buttons are asp buttons, we are not using the built-in export buttons.
So, once the export button is pressed the file is generated and all of our data that we want to be exported is however we have a problem where the first row in the grid is not being exported. In the export file, the first row is blank and the ID for the record does not show up in any other row.
Here is a scrubbed example:
https://www.dropbox.com/s/m562savvovi8fmp/GridExport_Scrubbed.csv?dl=0
Here is the grid definition:
<
telerik:RadGrid
ID
=
"ClaimExportGrid"
runat
=
"server"
AllowAutomaticUpdates
=
"false"
DataSourceID
=
"DDDClaimDS"
OnGridExporting
=
"OnClaimExportGridExporting"
AllowFilteringByColumn
=
"true"
AllowPaging
=
"true"
PageSize
=
"50"
VirtualItemCount
=
"50"
OnExcelExportCellFormatting
=
"OnClaimExportGridExcelExportFormatting"
OnItemCreated
=
"OnClaimExportGridItemCreated"
OnItemDataBound
=
"OnClaimExportGridItemDataBound"
OnUpdateCommand
=
"OnClaimExportGridUpdateCommand"
AutoGenerateColumns
=
"false"
>
<
ClientSettings
EnableRowHoverStyle
=
"true"
/>
<
ExportSettings
ExportOnlyData
=
"true"
FileName
=
"ClinicDDDExport"
HideStructureColumns
=
"True"
IgnorePaging
=
"true"
OpenInNewWindow
=
"true"
/>
<
MasterTableView
EditMode
=
"InPlace"
>
<
Columns
>
<
telerik:GridCheckBoxColumn
UniqueName
=
"BlkEdtEnabled"
AllowFiltering
=
"false"
Display
=
"false"
HeaderText
=
"Bulk Edit"
/>
<
telerik:GridCheckBoxColumn
UniqueName
=
"ChgInExptEnabled"
AllowFiltering
=
"false"
Display
=
"false"
HeaderText
=
"Change In Export"
/>
<
telerik:GridEditCommandColumn
UniqueName
=
"EditCommandColumn"
/>
<
telerik:GridBoundColumn
DataField
=
"LOC"
UniqueName
=
"LOC_Export"
AllowFiltering
=
"false"
HeaderText
=
"LOC"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"Contract"
UniqueName
=
"Contract_Export"
AllowFiltering
=
"false"
HeaderText
=
"Contract"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"Assist"
HeaderText
=
"Assist"
Display
=
"false"
AllowFiltering
=
"false"
UniqueName
=
"Assist_Export"
/>
<
telerik:GridBoundColumn
DataField
=
"Start Date"
HeaderText
=
"Start Date"
AllowFiltering
=
"false"
DataFormatString
=
"{0:MM/dd/yyyy}"
UniqueName
=
"StartDate_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"End Date"
HeaderText
=
"End Date"
AllowFiltering
=
"false"
DataFormatString
=
"{0:MM/dd/yyyy}"
UniqueName
=
"EndDate_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"CPT"
HeaderText
=
"CPT"
AllowFiltering
=
"true"
Display
=
"false"
UniqueName
=
"CPT_Export"
/>
<
telerik:GridBoundColumn
DataField
=
"Nursing"
HeaderText
=
"Nursing"
AllowFiltering
=
"false"
UniqueName
=
"Nursing_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"Units Delivered"
HeaderText
=
"Delivered"
AllowFiltering
=
"false"
DataFormatString
=
"{0:F2}"
UniqueName
=
"UnitsDelivered_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"Units Absent"
HeaderText
=
"Absent"
AllowFiltering
=
"false"
DataFormatString
=
"{0:F2}"
UniqueName
=
"UnitsAbsent_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"ServiceRate"
HeaderText
=
"ServRate"
AllowFiltering
=
"false"
DataFormatString
=
"{0:F2}"
UniqueName
=
"ServiceRate_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"TPLID1"
HeaderText
=
"TPL1ID"
AllowFiltering
=
"false"
UniqueName
=
"TPLID1_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"TPLReceived1"
HeaderText
=
"TPL1Rec"
AllowFiltering
=
"false"
DataFormatString
=
"{0:F2}"
UniqueName
=
"TPLReceived1_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"TPLCode1"
UniqueName
=
"TPL1Code_Export"
AllowFiltering
=
"false"
HeaderText
=
"TPL1Code"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"TPLID2"
HeaderText
=
"TPL2ID"
AllowFiltering
=
"false"
UniqueName
=
"TPLID2_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"TPLReceived2"
HeaderText
=
"TPL2Rec"
AllowFiltering
=
"false"
DataFormatString
=
"{0:F2}"
UniqueName
=
"TPLReceived2_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"TPLCode2"
UniqueName
=
"TPL2Code_Export"
AllowFiltering
=
"false"
HeaderText
=
"TPL2Code"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"TPLID3"
HeaderText
=
"TPL3ID"
AllowFiltering
=
"false"
UniqueName
=
"TPLID3_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"TPLReceived3"
HeaderText
=
"TPL3Rec"
AllowFiltering
=
"false"
DataFormatString
=
"{0:F2}"
UniqueName
=
"TPLReceived3_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"TPLCode3"
UniqueName
=
"TPL3Code_Export"
AllowFiltering
=
"false"
HeaderText
=
"TPL3Code"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"DDDSubmit"
HeaderText
=
"DDDSubmit"
AllowFiltering
=
"false"
DataFormatString
=
"{0:F2}"
UniqueName
=
"DDDSubmit_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"ProvCtrl"
HeaderText
=
"ProvCtrl"
AllowFiltering
=
"false"
UniqueName
=
"ProvCtrl_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"AHCCCSID"
HeaderText
=
"AHCCCSID"
AllowFiltering
=
"false"
UniqueName
=
"AHCCCSID_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"ClaimID"
HeaderText
=
"ClaimID"
AllowFiltering
=
"false"
UniqueName
=
"ClaimID_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"NPI"
HeaderText
=
"NPI"
AllowFiltering
=
"false"
UniqueName
=
"NPI_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"PlaceOfService"
HeaderText
=
"PlaceOfService"
AllowFiltering
=
"false"
UniqueName
=
"POS_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"SupName"
HeaderText
=
"SupervisorName"
AllowFiltering
=
"false"
UniqueName
=
"SupName_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"TherapistName"
HeaderText
=
"RenderTherapistName"
AllowFiltering
=
"false"
UniqueName
=
"TherapistName_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"PatientName"
HeaderText
=
"PatientName"
AllowFiltering
=
"false"
UniqueName
=
"PatientName_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"Tier"
HeaderText
=
"Tier"
AllowFiltering
=
"false"
UniqueName
=
"Tier_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"ModifiedOn"
HeaderText
=
"ModifiedOn"
AllowFiltering
=
"false"
UniqueName
=
"ModifiedOn_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"ModifiedBy"
HeaderText
=
"ModifiedBy"
AllowFiltering
=
"false"
UniqueName
=
"ModifiedBy_Export"
Display
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"ClaimID"
HeaderText
=
"ClaimID"
AllowFiltering
=
"false"
UniqueName
=
"ClaimID"
/>
<
telerik:GridBoundColumn
DataField
=
"PatientID"
HeaderText
=
"PatientID"
AllowFiltering
=
"false"
UniqueName
=
"PatientID"
/>
<
telerik:GridBoundColumn
DataField
=
"Assist"
HeaderText
=
"Assist"
AllowFiltering
=
"false"
UniqueName
=
"Assist"
/>
<
telerik:GridBoundColumn
DataField
=
"Start Date"
HeaderText
=
"Start Date"
AllowFiltering
=
"false"
DataFormatString
=
"{0:MM/dd/yyyy}"
UniqueName
=
"StartDate"
/>
<
telerik:GridBoundColumn
DataField
=
"End Date"
HeaderText
=
"End Date"
AllowFiltering
=
"false"
DataFormatString
=
"{0:MM/dd/yyyy}"
UniqueName
=
"EndDate"
/>
<
telerik:GridBoundColumn
DataField
=
"CPT"
HeaderText
=
"CPT"
AllowFiltering
=
"false"
UniqueName
=
"CPT"
/>
<
telerik:GridBoundColumn
DataField
=
"Units Delivered"
AllowFiltering
=
"false"
HeaderText
=
"Delivered"
DataFormatString
=
"{0:F2}"
UniqueName
=
"UnitsDelivered"
/>
<
telerik:GridBoundColumn
DataField
=
"Units Absent"
AllowFiltering
=
"false"
HeaderText
=
"Absent"
DataFormatString
=
"{0:F2}"
UniqueName
=
"UnitsAbsent"
/>
<
telerik:GridBoundColumn
DataField
=
"ServiceRate"
AllowFiltering
=
"false"
HeaderText
=
"Serv. Rate"
DataFormatString
=
"{0:F2}"
UniqueName
=
"ServiceRate"
/>
<
telerik:GridBoundColumn
DataField
=
"TPLID1"
AllowFiltering
=
"false"
HeaderText
=
"TPL1 ID"
UniqueName
=
"TPLID1"
/>
<
telerik:GridBoundColumn
DataField
=
"TPLReceived1"
HeaderText
=
"TPL1 Recv."
AllowFiltering
=
"false"
DataFormatString
=
"{0:F2}"
UniqueName
=
"TPLReceived1"
/>
<
telerik:GridBoundColumn
DataField
=
"DDDSubmit"
HeaderText
=
"DDD Submit"
AllowFiltering
=
"false"
DataFormatString
=
"{0:F2}"
UniqueName
=
"DDDSubmit"
/>
<
telerik:GridBoundColumn
DataField
=
"RenderingTherapistID"
AllowFiltering
=
"false"
HeaderText
=
"RenderingTherapistID"
UniqueName
=
"RenderingTherapistID"
/>
<
telerik:GridBoundColumn
DataField
=
"EmployeeID"
HeaderText
=
"SupervisorID"
AllowFiltering
=
"false"
UniqueName
=
"EmployeeID"
/>
<
telerik:GridBoundColumn
DataField
=
"SupNAme"
HeaderText
=
"Supervisor Name"
AllowFiltering
=
"false"
UniqueName
=
"SupName"
/>
<
telerik:GridBoundColumn
DataField
=
"AHCCCSID"
HeaderText
=
"AHCCCS ID"
AllowFiltering
=
"false"
UniqueName
=
"AHCCCSID"
/>
<
telerik:GridBoundColumn
DataField
=
"NPI"
HeaderText
=
"NPI"
AllowFiltering
=
"false"
UniqueName
=
"NPI"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
Here are the sections of the code where we are dealing with the grid before export:
OnItemDataBound event:
If ViewState("BExported") Then
If Not bCallOnce Then
EnableExportCols()
bCallOnce = True
End If
If eItmMap.Count > 0 Then
Dim conStr As String = ConfigurationManager.ConnectionStrings("H2T2SQLDBCConnectionString").ConnectionString
Dim newNPI As String = ""
Dim newAhcccsID As String = ""
If eItmMap.ContainsKey(grdDataItm.Item("ClaimID").Text) Then
Using con As New SqlConnection(conStr)
Using cmd As New SqlCommand("Select @AHCSID = AHCCCSID, @NPI = NPI from TherapistCredentials where EmployeeID = @NewSupID", con)
cmd.Parameters.Add("@NewSupID", SqlDbType.Int).Value = eItmMap(grdDataItm.Item("ClaimID").Text).GetSupID()
cmd.Parameters.Add("@AHCSID", SqlDbType.VarChar, 10)
cmd.Parameters.Add("@NPI", SqlDbType.VarChar, 20)
cmd.Parameters("@AHCSID").Direction = ParameterDirection.Output
cmd.Parameters("@NPI").Direction = ParameterDirection.Output
con.Open()
cmd.ExecuteNonQuery()
con.Close()
newNPI = If(IsDBNull(cmd.Parameters("@NPI").Value), "", cmd.Parameters("@NPI").Value)
newAhcccsID = If(IsDBNull(cmd.Parameters("@AHCSID").Value), "", cmd.Parameters("@AHCSID").Value)
grdDataItm.Item("NPI_Export").Text = newNPI
grdDataItm.Item("AHCCCSID_Export").Text = newAhcccsID
End Using
End Using
End If
End If
Else
......
EnableExportCols Function:
Private Sub EnableExportCols()
For Each col As GridColumn In ClaimExportGrid.MasterTableView.Columns
If TypeOf col Is GridBoundColumn Then
Dim bCol As GridBoundColumn = CType(col, GridBoundColumn)
If bCol.UniqueName.Contains("Export") Then
bCol.Visible = True
bCol.Display = True
Else
bCol.Visible = False
bCol.Display = False
End If
End If
Next
End Sub
As you can see in the attached csv file, the first row is missing and the ID CL 733083 is not present in the file. How can we resolve this?
Thanks.