- reporting_kit_conversion_demo.zip
- reports
- bin
- ASPNETReports.dll
- ASPNETReports.dll.bak
- MySql.Data.dll
- MySql.Data.Tests.dll
- MySql.Data.xml
- ChartGenerator.aspx
- components
- crosstab.aspx
- default.aspx
- docs
- drilldown.aspx
- Global.asax
- hierarchical.aspx
- images
- 1x1.gif
- asp.net-reports.gif
- background.gif
- crosstab.gif
- crosstabnestedcontrols.png
- crosstabtotals.png
- customers.gif
- drilldown.gif
- drilldownnestedcontrols.png
- employees.gif
- getorderdetails.gif
- GetOrders.gif
- grid_background.gif
- hierarchal.gif
- hierarchical.gif
- hierarchicalpaging.gif
- hierarchicalreport.gif
- hierarchicalschema.gif
- hierarchicalsorting.gif
- logo.gif
- logo-neg.gif
- masterdetail.gif
- masterdetaildetails.png
- masterdetails.gif
- masterdetailsummary.png
- masterdetailtables.png
- matrix.gif
- querysample.gif
- querysample2.gif
- reporting.gif
- report-table-bg.gif
- simple.gif
- simpleoverview.png
- simplesp.png
- spacer.gif
- tabcolorcode.png
- tabdetail.png
- tabheader.gif
- tabheader.png
- tabnestedcontrols.png
- tabsortshot.png
- tabular.gif
- tabularcolorcode.png
- tabularextendedprice.png
- tabularsorting.png
- text.gif
- textalternate.gif
- textreport.gif
- textshot.gif
- viscategorysales.gif
- viscategorysales.png
- vischartstructure.png
- visual.gif
- xtabsql.png
- masterdetail.aspx
- scripts.js
- simplereport.aspx
- sourceviewer
- 1x1.gif
- crosstab.src
- drilldown.src
- grid_background.gif
- hierarchical.src
- masterdetail.src
- simple.src
- srcview.aspx
- style.css
- tabular.src
- tabview.aspx
- textreport.src
- visual.src
- sql
- styles.css
- stylesPrint.css
- tabular.aspx
- textreport.aspx
- visual.aspx
- web.config
|
<%@ Page language="c#" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="ASPNET.StarterKit.Reports.Components" %>
<script runat="server">
//*********************************************************************
//
// Tabular.aspx
//
// The Tabular.aspx page shows a basic technique for grouping related data
// (in this case, grouping products by category). This is accomplished by nesting a
// DataGrid control inside a DataList control. Additionally, this report demonstrates
// how easy it is to implement interactive sorting in the report using ASP.NET.
//
//*********************************************************************
protected string _styleSheet;
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
// default sort will be by product name
if (SortField == "")
SortField = "ProductName";
BindList();
}
// switches the style sheet based on printer friendly view or not
if (Request.QueryString["Print"]=="true")
{
_styleSheet = "stylesPrint.css";
PrintButton.Visible = true;
}
else
{
_styleSheet = "styles.css";
}
}
//*********************************************************************
//
// The BindList method retrieves the list of categories
// and then data binds them to the ProductsByCategoryList
//
//*********************************************************************
private void BindList()
{
CategoriesList.DataSource = TabularReport.GetCategories();
CategoriesList.DataBind();
}
//*********************************************************************
//
// The GetDetails method calls the BLL to retrieve product for a category given
// a category id.
//
//*********************************************************************
protected TabularReportCollection GetDetails(int categoryID)
{
TabularReportCollection detailList = TabularReport.GetProducts(categoryID);
// do the sorting if there are data returned
if (detailList.Count > 0)
SortGridData(detailList, SortField, SortAscending);
return detailList;
}
//*******************************************************
//
// SortGridData methods sorts the datagrid based on which
// sort field is being selected. Also does reverse sorting based on the boolean.
//
//*******************************************************
private void SortGridData(TabularReportCollection list, string sortField, bool asc)
{
TabularReportCollection.TabularReportFields sortCol = TabularReportCollection.TabularReportFields.InitValue;
switch(sortField)
{
case "ProductName":
sortCol = TabularReportCollection.TabularReportFields.ProductName;
break;
case "UnitPrice":
sortCol = TabularReportCollection.TabularReportFields.UnitPrice;
break;
case "UnitsInStock":
sortCol = TabularReportCollection.TabularReportFields.UnitsInStock;
break;
}
list.Sort(sortCol, asc);
}
//*******************************************************
//
// CalculateExtendedPrice event handler is tied to the OnItemDataBound of the Datagrid.
// It retrieves the unit price and multiplies that to the units in stock to calculate the extended price of a product.
// The extended price is displayed as the right most column.
//
//*******************************************************
protected void CalculateExtendedPrice(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
double unitsInStock = Convert.ToDouble(e.Item.Cells[1].Text);
double unitPrice = Convert.ToDouble(e.Item.Cells[4].Text);
e.Item.Cells[5].Text = string.Format("{0:c}", unitPrice * unitsInStock);
// format unit price column as currency
e.Item.Cells[4].Text = string.Format("{0:c}", unitPrice);
// if there are no units in stock, color the line item as red by changing the style class
if (unitsInStock == 0)
e.Item.CssClass = "OutOfStock";
}
}
//*********************************************************************
//
// The SortGrid event handler changes the sortfield for the Projects grid
// and re-binds it.
//
//*********************************************************************
protected void SortGrid(Object sender, DataGridSortCommandEventArgs e)
{
// change sort field
SortField = (string)e.SortExpression;
// re-bind to display new sorting
BindList();
}
string SortField
{
get
{
object o = ViewState["SortField"];
if (o == null)
{
return String.Empty;
}
return (string)o;
}
set
{
if (value == SortField)
{
// same as current sort file, toggle sort direction
SortAscending = !SortAscending;
}
ViewState["SortField"] = value;
}
}
//*********************************************************************
//
// SortAscending property is tracked in ViewState
//
//*********************************************************************
bool SortAscending
{
get
{
object o = ViewState["SortAscending"];
if (o == null)
{
return true;
}
return (bool)o;
}
set
{
ViewState["SortAscending"] = value;
}
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Tabular</title>
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<link href="<%= _styleSheet %>" type=text/css rel=stylesheet>
<script src="scripts.js"></script>
</HEAD>
<body class="Report" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
<form id="Tabular" method="post" runat="server">
<table border="0" cellpadding="5" cellspacing="15" width="100%">
<tr>
<td class="ReportTitle">Products By Category</td>
<td align="right"><asp:HyperLink id="PrintButton" NavigateUrl="javascript:Print()" CssClass="printbutton" runat="server" Visible="False">Print</asp:HyperLink></td>
</tr>
</table>
<asp:datalist id="CategoriesList" runat="server" RepeatDirection="Vertical" repeatcolumns="1" Width="100%" CellPadding="5" cellspacing="15">
<itemtemplate>
<table border="0" cellpadding="3" cellspacing="0" class="Content" width="100%">
<tr>
<td valign="top" class="CategoryHeader">
Category
<%# DataBinder.Eval(Container.DataItem, "CategoryName") %>
</td>
</tr>
<tr>
<td>
<asp:datagrid id=Datagrid1 runat="server" autogeneratecolumns="False" DataSource='<%# GetDetails((int)DataBinder.Eval(Container.DataItem, "CategoryID")) %>' OnItemDataBound="CalculateExtendedPrice" BorderWidth="0" GridLines="None" AllowSorting="true" OnSortCommand="SortGrid" Width="100%">
<columns>
<asp:boundcolumn DataField="ProductName" HeaderText="Product" SortExpression="ProductName" ItemStyle-CssClass="ItemStyle" HeaderStyle-CssClass="ProductHeader" ItemStyle-Width="200"></asp:boundcolumn>
<asp:boundcolumn DataField="UnitsInStock" HeaderText="Units In Stock" ItemStyle-CssClass="ItemStyleRight" HeaderStyle-CssClass="ProductHeaderRight" SortExpression="UnitsInStock"></asp:boundcolumn>
<asp:templatecolumn>
<itemtemplate>
<img src="/reports/images/spacer.gif" width="70" height="1" />
</itemtemplate>
</asp:templatecolumn>
<asp:boundcolumn DataField="QuantityPerUnit" HeaderText="Quantity Per Unit" ItemStyle-CssClass="ItemStyle" HeaderStyle-CssClass="ProductHeader"></asp:boundcolumn>
<asp:boundcolumn DataField="UnitPrice" HeaderText="Unit Price" ItemStyle-CssClass="ItemStyleRight" HeaderStyle-CssClass="ProductHeaderRight" SortExpression="UnitPrice"></asp:boundcolumn>
<asp:boundcolumn HeaderText="Extended Price" ItemStyle-CssClass="ItemStyleRight" HeaderStyle-CssClass="ProductHeaderRight" DataField="UnitPrice"></asp:boundcolumn>
</columns>
</asp:datagrid>
</td>
</tr>
<tr>
<td class="CategoryFooter">
Total Units in Stock:
<%# DataBinder.Eval(Container.DataItem, "TotalInStock") %>
</td>
</tr>
</table>
</itemtemplate>
<headerstyle cssclass="ReportTitle"></headerstyle>
</asp:datalist>
</form>
</body>
</HTML>
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.