Repeater Control – Tips

28 08 2008

My recent project had a requirement to change the class for every fifth element in the repeater. Though I wasnt able to find it widely on the net, the coding turned to be easier than  I had ever imagined. Here’s the snippet that i used in the ItemDataBound event of the Repeater control to set the class for every fifth element:

private void rptCollections_ItemDataBound( object sender, RepeaterItemEventArgs
e ) {
   if ( ( e.Item.ItemType == ListItemType.Item  e.Item.ItemType ==
ListItemType.AlternatingItem )
      && ( 1 + e.Item.ItemIndex ) % 5 == 0 ) {
      HtmlGenericControl divAddressItem = e.Item.FindControl( “divAddressItem” ) as
HtmlGenericControl;
      divAddressItem.Attributes.Remove( “class” );
      divAddressItem.Attributes.Add( “class”, “lastItemCollectionItem” );
   }
}

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: