I recently had to change the class on every third data element in a repeater. And it turned out to be easier than I thought it might be, but I did not find it widely documented. The following snippet is called on the ItemDataBound event on the repeater and sets the class on a div for every third item in the repeater:
private void rptCollections_ItemDataBound( object sender, RepeaterItemEventArgs e ) {
if ( ( e.Item.ItemType == ListItemType.Item e.Item.ItemType == ListItemType.AlternatingItem )
&& ( 1 + e.Item.ItemIndex ) % 3 == 0 ) {
HtmlGenericControl divItem = e.Item.FindControl( "divItem" ) as HtmlGenericControl;
divItem.Attributes.Remove( "class" );
divItem.Attributes.Add( "class", "lastItemCollectionItem" );
}
}
Changing the display of every nth element in a repeater
Subscribe to:
Post Comments (Atom)
0 comments: (+add yours?)
Post a Comment