asp.net repeater Add Ordinal column method _ Practical Tips

Source: Internet
Author: User
In the project development process, you will often encounter ASP.net repeater control to add ordinal columns, some novice may not, online collection of some, need friends can refer to the

asp.net repeater add an ordinal column

1, <itemtemplate>
<tr><td>
<%# Container.itemindex + 1%>
</td></tr>
</itemtemplate>

2, <itemtemplate>
<tr><td>
<%# This.rpResult.Items.Count + 1%>
</td></tr>
</itemtemplate>

3. Add <label id= "dd" ></Label> in <form></form>
<body nload= "Show ()" >
<script. language= "JScript" >
Function Show ()
{
var bj = document.all.tags ("LABEL");
for (i=0;i<obj.length;i++)
{
document.all["DD"][I].INNERHTML=I+1;
}
}
</script>

4, Backstage realization method
Add <asp:label id= "Label1" runat= "Server" in. aspx ></asp:Label>
Add 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);
}
}
Add HTML based on criteria
<% #Container. ItemIndex = 8? "<br><a href = ' http://www.ginchan.com.tw/' target= ' _blank ' > </a> ': ""%>
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.