0

I have List of checkbox in my view. it shows me in vertical format. Like

a

b

c

d

...

But i want to format that in such a way that will look like.

a b c d

e f g h

i j k l

My code looks like this

 @foreach (var item in Model)
  {
  <table>
      <tr>
         <td><input type="checkbox" id="@item.DataId" name="Data"/>@item.DataName</td>
      </tr>
  </table>

How can i format this?

2 Answers 2

1

Hoping you're not using the table for layout purposes ;)

Anyway this should do the trick, it's rough code, and could be polished but hopefully this will give you a good start

<table>
    <tr>
@{var rower = 0;}
    @foreach (var item in Model)
    {
        if (rower % 4 == 0 && rower != 0)
        {
            @:</tr>
            @:<tr>
        }
         <td><input type="checkbox" id="@item.DataId" name="Data"/>@item.DataName</td>
        rower++;
    }
    </tr>
</table>
Sign up to request clarification or add additional context in comments.

Comments

0

Assuming you need a list, not a table:

// You may to check here whether model contains any items

<ul>
@foreach (var item in Model)
{
   <li><input type="checkbox" id="@item.DataId" name="Data"/>@item.DataName</li>
}
</ul>

In your CSS you need to set display property of the list to inline

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.