0

I have this list below, which I am generating on the fly using Razor view:

<table id="contractCoverablesGrid">
    <tbody>
        @foreach (var coverableItem in Model.ContractCoverablesList)
        {
            <tr>
                <td>
                    @Html.Hidden("coverID",coverableItem.CoverID)
                </td>
                <td>
                    @Html.Label(coverableItem.Name)
                </td>
                <td>
                    <input type='checkbox' class='chkboxActive' checked='checked' />
                </td>
            </tr>
        }
    </tbody>
</table>

As you can imagine the outcome of this is a vertical list, which keeps extending downwards.

I would like to have this list 'wrapped' into three adjacent columns instead of one single long column; just as you would do this in ASP.net Datalist server control (in Webforms).

My initial thoughts were to limit the width & height of the table to set values and then keep floating the td(s) left. But how do I float a td. I cannot turn this into div.

Any thoughts?

Please let me know.

2 Answers 2

1

You might try a for instead of foreach. You would loop through the list divided by 3 and start a new td each time.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, I have solved it little differently as you can see above.
1

This is how I resolved it:

<table id="contractCoverablesGrid" width="600" align="center">
    <tbody>
        <tr>
            @foreach (var coverableItem in Model.ContractCoverablesList)
            {
                <td>
                    <div id="dataListItem">
                        @Html.Hidden("coverableID", coverableItem.CoverID)
                        @Html.Label(coverableItem.Name)
                        <input type='checkbox' name="coverableItemCheckBox" id="coverableItemCheckBox" />
                    </div>
                </td>
            }
        </tr>
    </tbody>
</table>

<style>
    #dataListItem {
        float: left;
        font-weight: normal;
    }
</style>

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.