'''
''' Override the ${Export Button}_Click and customize the
''' export button functionality
''' Also if the export button is Image button then, second parameter type is ImageClickEventArgs.
''' If the button is of "Button" type then modify the parameter type to EventArgs.
'''
Public Overrides Sub ${Export Button}_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
Try
DbUtils.StartTransaction()
Dim whereStr As WhereClause = Me.CreateWhereClause()
'Create the order by object.
Dim ob As BaseClasses.Data.OrderBy = Nothing
' Set page index and size
Dim pageIndex As Integer = 0
Dim pageSize As Integer = 1000
' Get the instance of Data Access class.
Dim recList() As ${${Table}RecordClassName} = ${${Table}ClassName}.GetRecords(whereStr, ob, pageIndex, pageSize)
Dim exportedData As String = ""
exportedData = Me.ExportFunction(recList)
' Export the data.
Me.Page.AttachFile("MyFile.csv", exportedData)
Catch ex As Exception
' Report error message to the user
Utils.MiscUtils.RegisterJScriptAlert(Me, "UNIQUE_SCRIPTKEY", ex.Message)
Finally
DbUtils.EndTransaction()
End Try
End Sub
'''
''' This method limits the number of columns that get exported.
'''
Public Function ExportFunction(ByRef recList() As ${${Table}RecordClassName}) As String
' Add column names to the export data.
Dim exportLine As String = ${${Table}ClassName}.${Primary Key}.InternalName & ","
exportLine &= ${${Table}ClassName}.${Export Field}.InternalName & ","
' Finally, add the line break after adding the last column heading.
Dim exportedData As String = exportLine & vbCrLf
' Get column values from each record in table.
Dim rec As ${${Table}RecordClassName}
For Each rec In recList
exportLine = ""
exportLine &= rec.${Primary Key} & ","
exportLine &= rec.${Export Field} & ","
' Add the line break after each record.
exportedData &= exportLine & vbCrLf
Next
Return exportedData
End Function
|