5 ways to add an ordinal to a repeater control

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.