5 ways to add an ordinal to a repeater control
. NET is a very popular program-compiling language, and among the many points of knowledge in . NET Training , the 5 ways to add an ordinal to a repeater control are very important. The following is the Dahne 's teacher to introduce you to this aspect of the content.
Repeater is a data control that we often use to display data sets, and often we want to show the ordinal of the data before the data, so how do we add a sequence number for the Repeater control? The following edits describe several common ways to add an ordinal to a repeater control:
Method One:
Using the Container.itemindex property, the code is as follows:
<itemtemplate >
<%# Container.itemindex + 1% >
</itemtemplate >
Method Two:
Using Repeater's Items.Count attribute, the code is as follows:
<itemtemplate >
<%# this. Repeater.Items.Count + 1% >
</itemtemplate >
Method Three:
Use JS in the foreground to assign a label label, the code is as follows:
Add a Label control to the. aspx to display the ordinal number.
<label id= "Label" runat= "Server" ></label >
JS Code:
<body onload= "Show ()" >
<script language= "JavaScript" >
Function Show ()
{
var bj = document.all.tags ("label generated HTML tag after explanation");
for (i=0;i<obj.length;i++)
{
document.all["label generated HTML tag after explanation"][I].INNERHTML=I+1;
}
}
</script >
This method needs to pay attention to the place is more, is not recommended to use.
Method Four: Implemented in the background, the code is as follows:
Add a Label control in. aspx
<asp:label id= "Label1" runat= "Server" ></asp:label >
Add code in. CS:
void InitializeComponent ()
{
This. Repeater1.itemdatabound + = new System.Web.UI.WebControls.RepeaterItemEventHandler (this. Repeater1_itemdatabound);
This. Load + = new System.EventHandler (this. Page_Load);
}
void Repeater1_itemdatabound (object source, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if (E.item.itemtype = = ListItemType.Item | | e.item.itemtype = = listitemtype.alternatingitem)
{
(Label) E.item.findcontrol ("Label1"). Text = convert.tostring (E.item.itemindex + 1);
}
}
Method Five: Add a serial number for the Repeater control, followed by the number of pages before the page, the code is as follows:
<%# Container.itemindex + 1 + (this. ASPNETPAGER.CURRENTPAGEINDEX-1) * Number of data per page >
The content of the 5 ways to add serial numbers to the Repeater control has been introduced by the instructor of Dahne training , and I hope the content of this article will be helpful to the students.
5 ways to add an ordinal to a repeater control