MasterDetail.aspx Page

Description:   The Master Detail page displays a list of orders filtered by year and optionally by quarter. It provides a summary breakdown by quarter as well as a more detailed list of all orders for the year and quarter.

Overview:   This reports show a simple way of creating and databinding two different DataGrids on the same page, one for the summary and one for the details. Both DataGrids are bound to two separate stored procedures. For the summary, the results are filtered by year. For the details, the results are filtered by year and quarter (optional).

The summary breaks down the number of orders shipped and the amount of sales by quarter. The Sales Total for the year is reported at the bottom of the summary.

The detail displays a list of all the orders for the year and quarter (optional), reporting on it's Order ID, Order Date, and Sales amount.

The user can specify the year and quarter by selecting them from the YearDropDownList and QuarterDropDownList at the top of the page.

Implementation Notes:     Two separate DataGrids are created and binded to two separate stored procedures named GetOrderSummary and GetOrderDetails. This is done by calling GetSales and GetSalesDetails in the MasterDetail component in the Business Logic Layer, which will utilize the SQLHelper (DAAB) component in the Data Access Layer. Note that the YearDropDownList is used to pass in the year which the results are filtered by.

    Private Sub BindSummary()
        SummaryLabel.Text = YearDropDownList.SelectedItem.Text + " Summary"
        SummaryDataGrid.DataSource = GetSales(Convert.ToInt32(YearDropDownList.SelectedItem.Value))
        SummaryDataGrid.DataBind()
    End Sub 'BindSummary

    Protected Function GetSales(ByVal year As Integer) As MasterDetailReportCollection
        Return MasterDetailReport.GetSummary(year)
    End Function 'GetSales
		

In order to calculate the Sales Total , an event handler is added to the Summary DataGrid. We iterate thru the DataGrid's list of table rows. We use the third cell in each row, which represents the Sales column, to calculate the sales total. This total is then added back to the actual DataGrid's footer row.

    Private Sub SumItems(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles SummaryDataGrid.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            CalcTotal(e.Item.Cells(2).Text)
            e.Item.Cells(2).Text = String.Format("{0:c}", Convert.ToDouble(e.Item.Cells(2).Text))
        Else
            If e.Item.ItemType = ListItemType.Footer Then
                e.Item.Cells(0).Text = "Sales Total"
                e.Item.Cells(2).Text = String.Format("{0:c}", _salesTotal)
            End If
        End If
    End Sub 'SumItems

    Private Sub CalcTotal(ByVal _price As String)
        _salesTotal += [Double].Parse(_price)
    End Sub 'CalcTotal