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> ;
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