![]() | ||
|
Home
FAQ Examples Documentation Download Feedback Support |
demo6.aspx.cs
Return to Demo 6
Return to Examples
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ColaReport;
namespace ColaReportDemo
{
/// <summary>
/// Demonstrates:
/// Creating a link for a drill-down report.
/// The same type of thing can be done for other special formatting,
/// like including images.
/// </summary>
public class demo6 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblReport;
private void Page_Load(object sender, System.EventArgs e)
{
Report oReport;
CellColumn oCol;
Group oGroup;
DataSet dsRpt;
string sQuery;
OleDbConnection oConn;
OleDbDataAdapter daRpt;
// Get connection string
oConn = new OleDbConnection (ConfigurationSettings.AppSettings["gsConn"]);
//We later create a "group" on CustomerName.
//It is therefore important to order by CustomerName here.
sQuery = "SELECT c.CustomerId, c.CustomerName, c.City, c.State, sum(i.InvoiceTotal) as InvoiceTotal" +
" FROM Customer c, Invoice i" +
" WHERE c.customerid = i.customerid" +
" GROUP BY c.CustomerId, c.CustomerName, c.City, c.State" +
" ORDER BY c.CustomerName";
daRpt = new OleDbDataAdapter (sQuery, oConn);
dsRpt = new DataSet();
daRpt.Fill(dsRpt);
// Define Report
oReport = new Report ();
oReport.LinesPerPage = 33;
oReport.Style.Add ("font-family", "Verdana");
oReport.HeaderRowAttributes.Attributes["bgcolor"] = "#efefdf";
oReport.FirstPageHeader.Text = "<h2>Demo: demo6.aspx</h2>";
oReport.FirstPageHeader.Style.Add ("font-family", "Verdana");
oReport.PageHeader.Text = "<h3>Demo: demo6.aspx</h3>";
oReport.PageHeader.Style.Add ("font-family", "Verdana");
oCol = oReport.CreateCellColumn ("CustomerName", "Customer Name");
// Define the contents as a format string that can be made up of any
// number of data elements from the DataSet.
oCol.DefineFormat ("<a href='demo6a.aspx?customerid={0:g}'>{1:g}</a>", "CustomerId", "CustomerName");
oCol = oReport.CreateCellColumn ("City", "City");
oCol = oReport.CreateCellColumn ("State", "State");
oCol = oReport.CreateCellColumn ("InvoiceTotal", "Invoice Total");
oCol.SumColumn = true; //display totals for this column
oCol.Attributes["align"] = "right";
oCol.StringFormat = "{0:c}"; //currency format
//Total Group
oGroup = oReport.CreateTotalGroup (true);
oGroup.Cells["State"].Text = "Total";
oGroup.Cells.ApplyAttributeToAll("font-weight", "bold");
oGroup.BackColor = System.Drawing.Color.FromArgb (249,249,200);
oGroup.BlankLineAfterGroup = false;
//Bind dataset
oReport.Bind (dsRpt);
//Set label text to report output
lblReport.Text = oReport.Execute();
}
}
}
The code for demo6a.aspx.cs, the report that is linked to from demo6.aspx, appears below.
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ColaReport;
namespace ColaReportDemo
{
///
|
|