Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 122949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:12:34+00:00 2026-05-11T04:12:34+00:00

Often I find myself filling ASP.NET repeaters with items that need the CSS class

  • 0

Often I find myself filling ASP.NET repeaters with items that need the CSS class set depending on index: ‘first’ for index 0, ‘last’ for index (length-1), and ‘mid’ in the middle:

_repeater.DataSource = from f in foos                        select new                        {                          ...,                          CssClass = MakeCssClass( foos, f )                        };   private static string MakeCssClass( Foo[] foos, Foo f ) {   var index = Array.IndexOf( foos, f );    if( index == 0 )   {     return 'first';   }   else if( index == foos.Length - 1 )   {     return 'last';   }   else   {     return 'mid';   } } 

Is there a nicer way I can achieve this (eg using lambda functions)? If I try I get CS0828, ‘Cannot assign lambda expression to anonymous type property’.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T04:12:34+00:00Added an answer on May 11, 2026 at 4:12 am

    You might be interested in my SmartEnumerable type in MiscUtil.

    From the usage page, there’s an example:

    using System; using System.Collections.Generic;  using MiscUtil.Collections;  class Example {     static void Main(string[] args)     {         List<string> list = new List<string>();         list.Add('a');         list.Add('b');         list.Add('c');         list.Add('d');         list.Add('e');          foreach (SmartEnumerable<string>.Entry entry in                  new SmartEnumerable<string>(list))         {             Console.WriteLine ('{0,-7} {1} ({2}) {3}',                                entry.IsLast  ? 'Last ->' : '',                                entry.Value,                                entry.Index,                                entry.IsFirst ? '<- First' : '');         }     } } 

    With implicitly typed variables and a bit more type inference the syntax could be tidied up quite easily. I must get round to that some time, but the basics are already there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often find myself wanting to debug CSS layout issues that involve DOM changes
I often find myself remembering the name of a class that I want to
I often find myself asserting that an object isKindOfClass of some class in Objective-C.
I often find myself writing a property that is evaluated lazily. Something like: if
I often find myself needing reference to an object that is several objects away,
I often find myself with a list of disconnected Linq2Sql objects or keys that
I often find myself in need of writing down a future Visual Studio solution
I often find myself with fairly complex data that represents something that my objects
I often find myself designing simple little web projects that are serving up aggregate
I often find myself in need of very complex SQL examples when testing abstraction

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.