ColaReport - Demo 1
 Home
 FAQ
 Examples
 Documentation
 Download
 Feedback
 Support
  Demo 2       demo2.aspx.cs Complete Code       Return to Examples

This example builds off of the first example 1 and demonstrates other formatting, like setting the background to a different color for alternate rows.

Sample report output:

Demo: demo2.aspx

Name
Phone
Fax
 ABC Computers  508-555-1212  508-555-1213 
 Joe's Electronics  508-555-6543  508-555-6544 
 Bry's  650-555-9482  650-555-9483 
 Tech R Us  650-555-8392  650-555-8393 
 Schneider Computers  916-555-4938  650-555-4939 
 Mighty IT  714-555-8952  714-555-8960 

The beginning is very similar to Demo 1:

	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.Attributes["border"] = "0";

		oReport.FirstPageHeader.Text = "<h2>Demo: demo2.aspx</h2>";
		oReport.FirstPageHeader.Style.Add ("font-family", "Verdana");
		oReport.PageHeader.Text = "<h3>Demo: demo2.aspx</h3>";
		oReport.PageHeader.Style.Add ("font-family", "Verdana");

		oReport.HeaderRowAttributes.Attributes["bgcolor"] = "#efefdf";
      

We then set the row attributes differently for RowAttributes and RowAlternateAttributes to obtain alternating background colors.

		oReport.RowAttributes.Attributes["bgcolor"] = "#efefef";
		oReport.RowAlternateAttributes.Attributes["bgcolor"] = "#ffffff";
      

The column headers do not necessarily need to just contain text. They can contain any HTML, include TABLEs with borders to box them in. We use a couple of built in constants to make this easier.

		oCol = oReport.CreateCellColumn ("CustomerName", "Name"); 
		oCol.HeaderCell.Text = CellColumn.csBoxAndBoldStart 
			+ oCol.HeaderCell.Text + CellColumn.csBoxAndBoldEnd;

		oCol = oReport.CreateCellColumn ("Phone1", "Phone"); 
		oCol.HeaderCell.Text = CellColumn.csBoxAndBoldStart 
			+ oCol.HeaderCell.Text + CellColumn.csBoxAndBoldEnd;

		oCol = oReport.CreateCellColumn ("Fax", "Fax"); 
		oCol.HeaderCell.Text = CellColumn.csBoxAndBoldStart 
			+ oCol.HeaderCell.Text + CellColumn.csBoxAndBoldEnd;
      

Finally, we bind and output the report.

		
		//Bind dataset
		oReport.Bind (dsRpt);

		//Set label text to report output
		lblReport.Text = oReport.Execute();
	}
      
Copyright © 2003