locked
getting an value representing the number of the record in the result set RRS feed

  • Question

  • User379720387 posted

    In my scenario apptDays returns two records. When I hoover over apptDays and navigate the minuscule arrows to Results View it looks like this:

    [0] some information about this first record (multiple columns)

    [1] some information about this second record (multiple columns)

    var apptDays = dbContext.ScheduledSvcVisits
            .Where(s => s.enteredByProviderId == providerId && (s.visitStatus == "Scheduled" || s.visitStatus== "Invited"));

    Later in the code I have a foreach loop:

    foreach (var apptDay in apptDays)
    {
         <div id="@apptDay.?" class="panel-collapse collapse">
    }

    I need the div id to resolve to 0 and then 1 for the second time. How can I get those values from apptDay, without having a counter that increments on each pass?

    Friday, May 22, 2020 1:55 AM

Answers

  • User475983607 posted

    wavemaster

    I need the div id to resolve to 0 and then 1 for the second time. How can I get those values from apptDay, without having a counter that increments on each pass?

    I don't see how you can do this without a counter unless the results set has the values 0 and 1.  Maybe change to a for loop rather than a foreach.

    You can get the index but that causes a search over the collection by value which is not efficient.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 22, 2020 10:52 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 22, 2020 4:13 PM

All replies

  • User475983607 posted

    wavemaster

    I need the div id to resolve to 0 and then 1 for the second time. How can I get those values from apptDay, without having a counter that increments on each pass?

    I don't see how you can do this without a counter unless the results set has the values 0 and 1.  Maybe change to a for loop rather than a foreach.

    You can get the index but that causes a search over the collection by value which is not efficient.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 22, 2020 10:52 AM
  • User379720387 posted

    Ok, did it with a counter to move things along. Thanks

    Just out curiosity how does one get the index? 

    Friday, May 22, 2020 4:06 PM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 22, 2020 4:13 PM