Common Methods for adding serial numbers to the Repeater control

Source: Internet
Author: User

. Net is currently a very popular programming language. Among the many knowledge points in. net training, it is very important to add five serial numbers to the Repeater control. The following is a brief introduction of this content by Mr. Dana.

Repeater is a data control that we often use to display datasets. We often want to display data sequence numbers before data. How can we add sequence numbers for the Repeater control? The following describes several common methods to add sequence numbers for the Repeater control:

Method 1:
Using the Container. ItemIndex attribute, the Code is as follows:
Copy codeThe Code is as follows:
<Itemtemplate>
<% # Container. ItemIndex + 1%>
</Itemtemplate>

Method 2:
Use the Repeater's Items. Count attribute. The Code is as follows:
Copy codeThe Code is as follows:
<Itemtemplate>
<% # This. Repeater. Items. Count + 1%>
</Itemtemplate>

Method 3:
Use JS to assign a Label value to the front-end. The Code is as follows:

Add a Label control in. aspx to display the serial number.

<Label ID = "label" runat = "server"> </Label>

JS Code:
Copy codeThe Code is as follows:
<Body onload = "show ()">
<Script Language = "javascript">
Function show ()
{
Var bj = document. all. tags ("Html Tag generated by Label after explanation ");
For (I = 0; I <obj. length; I ++)
{
Document. all ["Html Tag generated after Label explanation"] [I]. innerHTML = I + 1;
}
}
</Script>

This method requires a lot of attention and is not recommended.

Method 4: the code is as follows:
Add a Label control in. aspx
Copy codeThe Code is as follows:
<Asp: Label id = "Label1" runat = "server"> </asp: Label>

Add code in. cs:
Copy codeThe Code is as follows:
Void InitializeComponent ()
{
This. Repeater1.ItemDataBound + = new System. Web. UI. WebControls. RepeaterItemEventHandler (this. repeaterincluitemdatabound );
This. Load + = new System. EventHandler (this. Page_Load );
}
Void repeaterincluitemdatabound (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 5: add consecutive numbers for the Repeater control. After turning pages, the serial number is followed by the serial number of the previous page. The Code is as follows:
Copy codeThe Code is as follows:
<% # Container. ItemIndex + 1 + (this. AspNetPager. CurrentPageIndex-1) * data volume per page>

The five methods for adding serial numbers to the Repeater control have been introduced by the internal training instructor. I hope this article will help students.

Related Article

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.