What is the best approach to have a single table column span across multiple columns on a page rather than having one column per page in ASP.NET MVC using C#?

Currently, I am working on creating a PDF view page for product labels using ASP.NET MVC in C#. The goal is to have two columns on the page, with 5 rows in each column, totaling to 10 labels per page. When specific products are selected in a form, the form should display a PDF view of the labels (using Rotativa) with the selected products inserted into the labels for printing. While I have managed to successfully populate the data into the labels, I'm facing an issue where the labels are displaying in a single column per page. What I want is for the labels to flow from one column to the next after reaching the end of a page, rather than starting a new page. I attempted to create another section and copied the fields from the first column, but it displayed duplicate records on each row. I've tried various solutions I found online, such as using display: block or display: inline-block, and setting column-count: 2; in CSS. However, none of these approaches have been successful. Most of the examples I came across online involve multiple fields or columns, but I only have one. It's puzzling that the labels repeat down the left half of the page but don't continue to the right half. The desired layout is as follows:

[ Label from Record 1 ] [ Label from Record 6 ]
[ Label from Record 2 ] [ Label from Record 7 ]
[ Label from Record 3 ] [ Label from Record 8 ]
[ Label from Record 4 ] [ Label from Record 9 ]
[ Label from Record 5 ] [ Label from Record 10]
(end of page 1)

I've been grappling with this issue for a couple of days now and any assistance would be greatly appreciated. Here is the code snippet I have so far:


   <table>
     @foreach (var item in Model)
     {
       <tr>
         <td class="left-col">
           <img src="@Server.MapPath("~/Images/" + item.Logo)" class="comp-logo"><br />
           <label class="item-lbl">Item #</label><br />
           <label class="code">@Html.DisplayFor(modelitem => item.Product_Code)</label><br />
           <label class="descript">@Html.DisplayFor(modelitem => item.Description)</label>
         </td>
       </tr>
     }
   </table>

Answer №1

If you don't want to use an HTML table tag, you can achieve a similar layout by wrapping the elements in a div and setting the div to display grid. By using grid template columns, you can specify the number of columns and their widths. In this example, I set them to 1fr 1fr, creating two columns with equal widths. You can also specify widths in pixels or percentages for more customization. The same principle applies to grid-template-rows.

<style>
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr 1fr 1fr;
  justify-content: start;
  width: max-content;
}
</style>
<div class="grid">
@foreach (var item in Model)
{
  <span class="left-col">
    <img src="@Server.MapPath("~/Images/" + item.Logo)" class="comp-logo"><br />
    <label class="item-lbl">Item #</label><br />
    <label class="code">@Html.DisplayFor(modelitem => item.Product_Code)</label><br />
    <label class="descript">@Html.DisplayFor(modelitem => item.Description)</label>
  </span>
}
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to ensure a div takes up the rest of the height on a page when the header's size is unpredictable

Is there a way to make the red area fill the remaining visible space without overlapping into the footer? I also need the infoContent section to be scrollable. The height of the header may vary. I came across some older solutions that suggested using Java ...

Material UI does not have built-in functionality for displaying colored text within a multiline textfield component in React

Attempting to utilize the material ui library in a react app has brought an issue to light. It appears that styling colored text does not work as expected for multiline textfields. Consider the following scenario: import React, { Component } from 'r ...

Is the contact form confirmation message displaying too prominently?

I am currently troubleshooting two different forms on a website I'm developing, and I am unsure of the exact cause of the issue. Form 1: Form 2: When attempting to submit Form 1 without entering any information, an error message is displayed exactl ...

Swap out the div block with a new one

I am currently facing an issue with my JavaScript code. The code is supposed to remove block1 and replace it with block2 when an onclick function is triggered. function buyerclick() { div = document.getElementById('block2'); div.style.displa ...

Tips for preventing text from breaking onto a new line in Safari

I have cforms plugin installed on a WordPress page. Interestingly, the word "required" in Russian appears to consist of two words as per the translation office. While it displays correctly in Firefox, in Safari it breaks and aligns to the bottom left of ...

Enhancing an element with a modifier in CSS using BEM conventions without the need for @extend

Trying to grasp the best method for writing BEM modifier rules within parent classes. I've utilized SASS's @extend but question if this is the right approach. For example: If there is a class called .form structured like this: <div className= ...

Determine the prior location of an element using jQuery

Is there a way to track the previous location of an element before it is appended? I have 50 elements that need to be appended to different targets based on a certain condition. How can I determine where each element was located before being moved? $(&a ...

Paste the URL into your clipboard without relying on JavaScript

Is there a way to implement a copy to clipboard function for email templates without relying on JavaScript? ...

Dealing with network errors post-testing in Selenium

The problem at hand In my search for a solution using C#, I have encountered several methods, but none have proven effective for my specific case. I am unable to utilize them due to missing objects that I can't import or objects that have been deprec ...

Repeated Hover Effects on CSS Menu Icons

the webpage I need help with is (issue with general menu drop down) Hello I recently decided to enhance my menu by incorporating icons. I had successfully implemented a drop-down menu using only HTML and CSS, but when I attempted to add icons next to ea ...

Filestack - NoCrop: Utilize whitespace to maintain the square aspect ratio when uploading images without cropping

Is there a way to use Filestack to upload an image and automatically add whitespace to the sides of the image in order to keep it square without cropping? click here for image ...

Blazor Bootstrap - Issue with Dropdown Remaining Open When Clicking Outside Element

Having trouble implementing the default Bootstrap dropdown behavior in my Blazor Server app. I need the dropdown menu to close when I click anywhere outside of it. I attempted using @onfocusout, but ran into issues. If I click inside a form input and then ...

Switch the Ionic Slide Box to the "does-continue" setting

Currently in the process of constructing a slide-box containing numerous items. I've borrowed the code from the example provided here for an infinite number of items, and it's performing well. However, I have a considerable yet finite amount of ...

Is there a way to have a span update its color upon clicking a link?

I have 4 Spans and I'm looking to create an interactive feature where clicking a link in a span changes the color of that span. Additionally, when another link in a different span is clicked, the color of that span changes while reverting the previous ...

Altering the placement of a single element from floating to fixed positioning in CSS

Currently in the process of designing a basic website, I am looking to modify the behavior of the navigation bar on the left-hand side. I want it to remain fixed in its position so that users can scroll through the page without losing sight of it. My main ...

Positioning an image on the left side of a div within a flex container using

Here is the code I have: .usp-bar { display: flex; flex-wrap: wrap; background-color: #005932; color: #fff; font-weight: 700; padding: 10px 0; margin-top: 0; ju ...

Tips for addressing duplicate values within a two-dimensional array

I am facing a challenge with a 2D array of characters that is 6x6 in size and looks like the following. I am attempting to create a method that will replace duplicate characters within a row with the '@' symbol. a b a a a a b c a a a b a a a ...

Confirming Steam ID ownership in a NET Core and React application

Currently, I am utilizing React for the frontend and .NET Core Web Api for the backend. The communication between the two servers is done via HTTP. I have a specific requirement to include a "Sign in through steam" button on my webpage that, when clicked, ...

Maintain the selected list item after filtering in AngularJS

I am facing an issue with highlighting selected items in a list. I have three first names: Roy, Sam, David displayed in a ul as list items. Initially, I can toggle each li on click just fine. However, after performing a search and returning to the list, th ...

"Enhance your website navigation with the Bootstrap BS3 navbar clc Dropdown-Submenu feature

Utilizing Bootstrap BS3 for the construction of my Django website. I created a dropdown-submenu that is operational on http://www.bootply.com/nZaxpxfiXz# https://i.sstatic.net/85uTq.png However, when implementing the same in my project, I encountered: h ...