Extending an ASP.NET Datagrid to Support Simple Cross Tab Reporting: The Source Code - Where does the processing start?
(Page 3 of 4 )
The processing starts when you call “LoadData.” The following is the code I wrote in “LoadData:”
Public Sub LoadData()
Dim dtReport As DataTable
Select Case TypeOfObject
Case ObjectType.Table
dtReport = getCrossTab_LevelSingle_ForTable()
Case ObjectType.StoredProcedure
dtReport = getCrossTab_LevelSingle_ForSP()
End Select
Me.DataSource = dtReport
Me.DataBind()
End Sub
It is really very simple. I just made it very precise for proper readability. Based on the data source (for retrieving information) provided by the user, the processing starts either at “getCrossTab_LevelSingle_FoTable” (for table) or “getCrossTab_LevelSingle_FoSP” (for stored procedure).
The following is the complete source code for the cross-tab engine (dealing with the table):
Private Function getCrossTab_LevelSingle_ForTable() As DataTable
Dim tblname As String = ObjectName
Dim SmryType As OperationType = Me.TypeOfOperation
Dim dtReport As New DataTable
'adding columns to the report data table
dtReport.Columns.Add("Details")
Dim dtColumns As DataTable = getDataTable("select distinct " & ColFieldName & " from " & tblname & " order by " & ColFieldName)
For Each drColumn As DataRow In dtColumns.Rows
dtReport.Columns.Add(drColumn(0))
Next
'additional blank columns
For i As Integer = 1 To AdditionalBlankColumns
dtReport.Columns.Add(New DataColumn)
Next
'adding rows to the report data table
Dim dtRowField As DataTable = getDataTable("select distinct " & RowFieldName & " from " & tblname & " order by " & RowFieldName)
For Each drRowField As DataRow In dtRowField.Rows
Dim drReport As DataRow = dtReport.NewRow
drReport("details") = drRowField(0)
For Each drColumn As DataRow In dtColumns.Rows
drReport(drcolumn(0)) = getRowValue("select " & [Enum].GetName(GetType(OperationType), SmryType) & "(" & SummaryFieldName & ") from " & tblname & " where " & RowFieldName & "='" & drRowField(0) & "' and " & ColFieldName & "='" & drcolumn(0) & "'")
Next
dtReport.Rows.Add(drReport)
Next
Return dtReport
End Function
The next section gives you the complete source code for the cross-tab engine (dealing with stored procedures).
Next: Cross-tab processing with the information from the stored procedure >>
More ASP.NET Articles
More By Jagadish Chaterjee