Example Analysis of dynamic column change of Repeater Control
This article will explain in detail the example analysis of dynamic column changes in Repeater controls. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Refactoring begins:
First of all, delete these five variables, because they are no longer needed during the refactoring process.
The copy code is as follows:
/ / declare five variables that will be used to store the number of each part in those five months
Decimal c1, c2, c3, c4, c5
The next thing to change is to declare a constant, which is used in many places:
The copy code is as follows:
Const int dynamicColumns = 5
Put the following sentence in the program
The copy code is as follows:
ObjPrintLog.Months = 5; / / for the last 5 consecutive months
Change to:
The copy code is as follows:
ObjPrintLog.Months = dynamicColumns
That is, use constant variables to replace the "5" of the old code.
Next, let's ReFactor the code for the Header of the Repwater control. For comparison, Insus.NET references the corresponding image from the previous article here:
Refactoring is as follows:
The copy code is as follows:
Protected void RepeaterLFMS_ItemDataBound (object sender, RepeaterItemEventArgs e)
{
If (e.Item.ItemType = = ListItemType.Header)
{
If (e.Item.FindControl ("LabelH0")! = null
& & e.Item.FindControl ("LabelH1")! = null
& & e.Item.FindControl ("LabelH2")! = null
& & e.Item.FindControl ("LabelH3")! = null
& & e.Item.FindControl ("LabelH4")! = null
& e.Item.FindControl ("LabelH5")! = null)
{
For (int I = 0; I