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 6847605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:45:54+00:00 2026-05-27T00:45:54+00:00

This is part of my timetable code Two questions : How can I prevent

  • 0

This is part of my timetable code

Two questions :

  1. How can I prevent having to loop through the times, and then the roombookings to check if it exists in the given time slot. Is there a way of just saying “for this time, is there a match(s) from this list and what is its Id”

  2. Is there anyway I can set the outer td to class bgred, rather than a span. (Note that there may be multiple bookings in a timeslot, hence having the td out of the foreach loop.)

<tr>
    <th></th>

        @for (int i = 9; i <= 17; i++)
        {
        <th>@i:00</th>
        }
</tr>

    @foreach (var RoomNo in ViewBag.Rooms)      
    {

        <tr>

            <th>@RoomNo</th>

           @for (int i = 9; i <= 17; i++)
           {
               <td>
               @foreach (var roombooking in ViewBag.RoomBookings)
               {
                   DateTime DateCheckStart = DateTime.Parse(ViewBag.Date.ToShortDateString() + " " + i.ToString() + ":00");
                   DateTime DateCheckEnd = DateTime.Parse(ViewBag.Date.ToShortDateString() + " " + i.ToString() + ":59");
                   if (DateCheckStart < roombooking.EndDateTime && DateCheckEnd > roombooking.StartDateTime && roombooking.RoomNo == RoomNo)
                   {
                     <span class="bgred"> @roombooking.RentalNo</span>
                   }
               }
               </td>
           }
        </tr>

     }
  • 1 1 Answer
  • 0 Views
  • 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. Editorial Team
    Editorial Team
    2026-05-27T00:45:55+00:00Added an answer on May 27, 2026 at 12:45 am

    Try something like this.

     <table>
    <tr>
        <th></th>
    
            @for (int i = 9; i <= 17; i++)
            {
            <th>@i:00</th>
            }
    </tr>
    
    @{ List<MyLibrary.MyRoomOccupancy> RoomBookingsTemp = ViewBag.RoomBookings;}
    
    @foreach (var RoomNo in ViewBag.Rooms)
    {
        <tr>
            <th>@RoomNo</th>
    
           @for (int i = 9; i <= 17; i++)
           {             
               DateTime DateCheckStart = DateTime.Parse(ViewBag.Date.ToShortDateString() + " " + i.ToString() + ":00");
               DateTime DateCheckEnd = DateTime.Parse(ViewBag.Date.ToShortDateString() + " " + i.ToString() + ":59");
    
               var sublist = (from RoomOcc in RoomBookingsTemp where DateCheckStart < RoomOcc.EndDateTime && DateCheckEnd > RoomOcc.StartDateTime && RoomOcc.RoomNo == RoomNo select RoomOcc);
    
    
               if (sublist.Count() > 0)
               {
                  @Html.Raw("<td class= \"bgred\">");
    
                }
               else {
                   Html.Raw("<td>");
               }
    
               foreach (var roombooking in sublist)
               {
                   if (DateCheckStart < roombooking.EndDateTime && DateCheckEnd > roombooking.StartDateTime && roombooking.RoomNo == RoomNo)
                   {
                      @roombooking.RentalNo
                   }
               }
               @Html.Raw("</td>");
    
           }
        </tr>
    
    }
    
    
    </table>
    

    What this does is it loops through onlyt he

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

Sidebar

Related Questions

Hi I have written this part of code .before the for loop I have
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
It seems that this part of my code is where the exception occurs: c
I am trying to learn and writting this part of code. while testing few
I just started learning C but I don't understand this part of the code.
The code we're using is straightforward in this part of the search query: myCriteria.Add(
This part of my code checks to see that when the user clicks on
So This part of my code: print_r($_SESSION['T']); $T = array_values($data2); print_r($_SESSION['T']); Outputs this: Array
I have this part of code that was compiling using ARMASM : /* Software
Why does this part of code fail: Integer.parseInt(11000000000000000000000000000000,2); Exception in thread main java.lang.NumberFormatException: For

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.