Anatoly Lubarsky

Logo
MSSQL, .NET, Design. Life and Music

ASP.NET tip: Autonumber Rows in ASP.NET Repeater control

Q: How to print the current row number in an ASP.NET Repeater control ?


A: The easiest way to autonumber rows in Repeater is to use markup or ItemDataBound event. Since each row has ItemIndex property when created/bounded. Therefore for Repeater markup one can write the following:


< ItemTemplate>
    < %# Container.ItemIndex + 1 %>
< /ItemTemplate>

Or in the ItemDataBound event (for more complex rendering) this should look like so:


if ((e.Item.ItemType == ListItemType.AlternatingItem) || 
    (e.Item.ItemType == ListItemType.Item))
{
    int num = e.Item.ItemIndex + 1;

    // some code
}

Enjoy :)


Related Posts:

Saturday, April 26, 2008 2:37 AM

If your feedback doesn't appear right away, please be patient as it may take a few minutes to publish.

Post a Comment

Protected by CAPTCHAEnter the code you see
Name (*)  
E-mail (*)  
Url
Remember

Comment (*)