Simple Report

Description:    The simple report displays a list of all customer contacts information for the company. This is useful for sales people who constantly are on the road since it is accessible from anywhere through the web.

Overview:    The simple report demonstrates using the Datagrid control for listing a result set from the database.


Implementation Notes:    

The Datagrid can also be used to support deleting and editing.  However, the purpose of this report is to show how simple and quick it is to display data from a database in an ASP.NET Web Form with paging and sorting features.

To allow paging, set the DataGrid AllowPaging property to true and create an event handler, PageIndexChanged, to change the CurrentPageIndex property.

		
    Private Sub CustomerGrid_PageIndexChanged(ByVal [source] As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles CustomerGrid.PageIndexChanged
        CustomerGrid.CurrentPageIndex = e.NewPageIndex
        BindGrid()
    End Sub 'CustomerGrid_PageIndexChanged
   

Implementing sorting is also as simple as paging:  set the AllowSorting to true, implement OnSort event handler, and set the SortExpression for each bound column.

		
    Private Sub CustomerGrid_Sort(ByVal [source] As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles CustomerGrid.SortCommand
        ' change sort field
        SortField = CStr(e.SortExpression)

        ' re-bind to display new sorting
        BindGrid()
    End Sub 'CustomerGrid_Sort
   

The Datagrid can also be custom formatted to the desired look and feel.  In this report page, customer contact information is displayed using alternating row color.  To enable this feature, simply assign a style to AlternatingItemStyle-CssClass attribute.

		
   <asp:datagrid id="CustomerGrid" AlternatingItemStyle-CssClass="Content" runat="server" AllowSorting="True" AllowPaging="True" PageSize="20">
   <AlternatingItemStyle CssClass="Content"></AlternatingItemStyle>
   <Columns>
   <asp:BoundColumn DataField="CompanyName" SortExpression="CompanyName" HeaderText="Company">
      <HeaderStyle CssClass="CategoryHeader"></HeaderStyle>
      <ItemStyle CssClass="ItemStyle"></ItemStyle>
   </asp:BoundColumn>