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 void CustomerGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
CustomerGrid.CurrentPageIndex = e.NewPageIndex;
BindGrid();
}
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 void CustomerGrid_Sort(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
// change sort field
SortField = (string)e.SortExpression;
// re-bind to display new sorting
BindGrid();
}
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>