Need to develop a small report showing the number of summary in the last five months, the report will change with the month, as shown below. The first column [Department] is fixed, second to sixth, that is, Nov 2012 will disappear in the next month, and the subsequent columns will move forward, and the last column of Mar 2013 will become Apr 2013.
In the following illustration, the bottom row shows the total number of each column (except for the first column).
For this report, Insus.net decided to use the Repeater control to implement it. The difficulty is in dynamic explicit column names in the second column to column sixth, and binding data. The last line to calculate the total, as long as the above dynamic binding is not a problem, repeater FooterTemplate display a column totals method, you can refer to this article: http://www.jb51.net/article/34972. HTM due to the entire report, the number of columns must be a total of six columns, so we can write this to death.
The first is HeaderTemplate, with a table in it, design six columns, pull a label per column, and set the ID of the label separately, preferably with an indexed ordinal:
Next is the ItemTemplate design, you can refer to the design of HeaderTemplate:
Finally, the design of the FooterTemplate, the design of the label ID,TD text alignment and background color:
The ID of three template labels is different, but there are some rules that make it easy to FindControl in the background and to refactor the control in the future.
The above is all HTML design, the following will be program development.
Copy Code code as follows:
Instantiate the object, and declare a DataTable object Objdt.
Printlog Objprintlog = new Printlog ();
DataTable Objdt;
Declares 5 variables that will be used to store the number of each part of the 5 month
Decimal C1, C2, C3, C4, C5;
To bind data obtained from a database to a Repeater control:
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Data_binding ();
}
}
private void Data_binding ()
{
((Iusercontrolcontainer) this. Master). Showcontrol = true;
CultureInfo ocultureinfo = new CultureInfo ("en"); Set up a good regional culture
DateTime currentdatetime = DateTime.Now; Get Current date Time
Objprintlog.year = Currentdatetime.year; Get year Assignment
Objprintlog.month = currentdatetime.month;//Get month assignment
Objprintlog.months = 5; 5 months in a row recently
OBJDT = Objprintlog.getsummaryreportbyyearmonth ();
This. Repeaterlfms.datasource = OBJDT;
This. Repeaterlfms.databind ();
}
The phone rang, you need to answer the phone first ... About a minute and 36 seconds to finish, and to coffee a cup of tea.
The following will be the Onitemdatabound event for the Repeater control, and insus.net also map out the Header,item and foot respectively:
Item bindings:
Finally, the foot code:
Oh, it's done. It is believed that it will move forward over time (changes in the month), its corresponding column name, and the data will change as it runs.