Generate "Ordinal" column in ASP. NET (C #)--repeater

Source: Internet
Author: User

Idea: Because the "ordinal" is related to the line number of repeater, the value of "ordinal" should be output in Repeater's ItemDataBound event. To make it easier to assign a value to "ordinal", we use a Label control.

Note: The itemindex of repeater is starting from 0, and the "ordinal" column is starting from 1, so itemindex to add 1.

The foreground code looks like this:

Front Code<asp:repeater id="Repeater1"runat="Server"Onitemdatabound="Repeater1_itemdatabound"> <HeaderTemplate> <table border="1"style="border-color: #000000; border-collapse:collapse; width:100% ;Text-align:center; Word-spacing:normal; font-size:13px;"cellpadding="5"><tr height=" -"style="background-color: #66CCFF; font-weight:bold;"> <td>Serial Number</td> <td>Contract Number</td> <td>Device Name</td> <td>Device Model</td> <td>Quantity</td> <td>Storage Time</td> <td>Operation</td> </tr> </HeaderTemplate> <ItemTemplate> <tr style='Background-color: <%# (container.itemindex%2==0)? " #eeeeee ":" #ffffff "%>'onmouseover="this.style.background= ' #ddeeff '"onmouseout="this.style.background= ' <%# (container.itemindex%2==0)?"#eeeeee":"#ffffff"%> '"> <td> <asp:label id="No"runat="Server"text=""></asp:Label> </td> <td> <%# DataBind Er. Eval (Container,"Dataitem.contract_no")%> </td> <td> <%# DataBinder.Eval (containe R"Dataitem.assets_name")%> </td> <td> <%# DataBinder.Eval (containe R"Dataitem.assets_model")%> </td> <td> <%# DataBinder.Eval (containe R"Dataitem.assets_amount")%> </td> <td> <%# DataBinder.Eval (containe R"Dataitem.in_time")%> </td> <td> <asp:hyperlink id="HyperLink1"runat="Server"target="_blank"Navigateurl='<%# "storage_details.aspx?storage_id=" +databinder.eval (Container, "dataitem.id")%>'text="Detail"></asp:HyperLink> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:repeater&gt ;

The background code looks like this:

Background Code protected void Repeater1_itemdatabound (object  sender, RepeaterItemEventArgs e)    {        if (E. Item.itemtype = = ListItemType.Item | | E.item.itemtype = = ListItemType.AlternatingItem        )            {= (Label) e.item.findcontrol (" No " );             = (1 + e.item.itemindex). ToString ();        }    }

Generate "Ordinal" column in ASP. NET (C #)--repeater

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.