![]() | |||||||||||||||||||||||
|
Home
FAQ Examples Documentation Download Feedback Support |
Demo 1
demo1.aspx.cs Complete Code
Return to Examples
This example demonstrates creating simple report listing. Sample report output: Demo: demo1.aspx
The code of Page_Load appears below:
private void Page_Load(object sender, System.EventArgs e)
{
CellColumn oCol;
Report oReport;
DataSet dsRpt;
string sQuery;
OleDbConnection oConn;
OleDbDataAdapter daRpt;
// Get connection string
oConn = new OleDbConnection (ConfigurationSettings.AppSettings["gsConn"]);
sQuery = "SELECT CustomerName, Phone1, Fax" +
" FROM Customer";
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"] = "#efefef";
oReport.FirstPageHeader.Text = "<h2>Demo: demo1.aspx</h2>";
oReport.FirstPageHeader.Style.Add ("font-family", "Verdana");
oReport.PageHeader.Text = "<h3>Demo: demo1.aspx</h3>";
oReport.PageHeader.Style.Add ("font-family", "Verdana");
oCol = oReport.CreateCellColumn ("CustomerName", "Name");
oCol = oReport.CreateCellColumn ("Phone1", "Phone");
oCol = oReport.CreateCellColumn ("Fax", "Fax");
//Bind dataset
oReport.Bind (dsRpt);
//Set label text to report output
lblReport.Text = oReport.Execute();
}
First, all needed variables are declared:
private void Page_Load(object sender, System.EventArgs e)
{
CellColumn oCol;
Report oReport;
DataSet dsRpt;
string sQuery;
OleDbConnection oConn;
OleDbDataAdapter daRpt;
Then, we initialize our connection, and execute some query to populate the DataSet containing the data to use. Note that we can also use a DataView instead of a DataSet.
// Get connection string
oConn = new OleDbConnection (ConfigurationSettings.AppSettings["gsConn"]);
sQuery = "SELECT CustomerName, Phone1, Fax" +
" FROM Customer";
daRpt = new OleDbDataAdapter (sQuery, oConn);
dsRpt = new DataSet();
daRpt.Fill(dsRpt);
Next, we instantiate a report. We set the number of lines per page, and set other formatting information.
// Define Report
oReport = new Report ();
oReport.LinesPerPage = 33;
oReport.Style.Add ("font-family", "Verdana");
oReport.HeaderRowAttributes.Attributes["bgcolor"] = "#efefef";
oReport.FirstPageHeader.Text = "<h2>Demo: demo1.aspx</h2>";
oReport.FirstPageHeader.Style.Add ("font-family", "Verdana");
oReport.PageHeader.Text = "<h3>Demo: demo1.aspx</h3>";
oReport.PageHeader.Style.Add ("font-family", "Verdana");
Now we define the columns that we want to appear in the report. The first argument to CreateCellColumn corresponds to the DataColumn in the DataSet. The second argument is for the column header that appears on the report.
oCol = oReport.CreateCellColumn ("CustomerName", "Name");
oCol = oReport.CreateCellColumn ("Phone1", "Phone");
oCol = oReport.CreateCellColumn ("Fax", "Fax");
Finally, we bind the DataSet to the report, and set the output of the report to the report label.
//Bind dataset
oReport.Bind (dsRpt);
//Set label text to report output
lblReport.Text = oReport.Execute();
}
|
||||||||||||||||||||||