SoFunction
Updated on 2025-03-07

Introduction to 5 common methods of adding serial numbers to Repeater controls

.net is a very popular program compilation language at present. Among the many knowledge points in .net training, 5 ways to add serial numbers to the Repeater control are very important. Below, Teacher Dane will introduce this content to you.

Repeater is a data control that we often use to display data sets. We often want to display the sequence number of the data in front of the data. So how should we add the sequence number to the Repeater control? The following editor will introduce several commonly used methods to add serial numbers to the Repeater control:

Method 1:
Using properties, the code is as follows:
Copy the codeThe code is as follows:

<Itemtemplate >
<%# + 1% >
</Itemtemplate >

Method 2:
Using the Repeater properties, the code is as follows:
Copy the codeThe code is as follows:

<Itemtemplate >
<%# + 1% >
</Itemtemplate >

Method 3:
Use JS to assign a Label tag to the foreground, the code is as follows:

Add a Label control to .aspx to display the sequence number.

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

JS code:
Copy the codeThe code is as follows:

<body onload="show()" >
<Script Language="javascript" >
function show()
{
var bj = ("Html tag generated by Label after interpretation");
for (i=0;i<;i++)
{
["Html tag generated by Label after explanation"][i].innerHTML=i+1;
}
}
</script >

There are many things to pay attention to in this method and are not recommended.

Method 4: Implement in the background, the code is as follows:
Add a Label control in .aspx
Copy the codeThe code is as follows:

<asp:Label runat="server" ></asp:Label >

Add code in .cs:
Copy the codeThe code is as follows:

void InitializeComponent()
{
this. += new (this.Repeater1_ItemDataBound);
+= new (this.Page_Load);
}
void Repeater1_ItemDataBound(object source, e)
{
if( == || == )
{
((Label)("Label1")).Text = ( + 1);
}
}

Method 5: Add continuous numbers to the Repeater control, and follow the serial number of the previous page after turning the page. The code is as follows:
Copy the codeThe code is as follows:

<%# + 1 + ( -1)*Number of data per page >

The content of 5 ways to add serial numbers to the Repeater control has been introduced to you by the instructor trained by Dane. I hope the content of this article can be helpful to the students.