Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Robert 63 posts 282 karma points
    Apr 03, 2015 @ 12:01
    Robert
    0

    Counting number of items

    Hi,

    I have a table and in the first column i want the number of the item. Example: for the first item i want the number 1 in the column, for the seconds item i want the number 2 in the column...

    How can this be done?

    This is my code so far:

    @foreach (var childPage in Table){
    <section class="section">
        <div class="container">
            <div class="row mb30">
                <div class="col-sm-12">
                    <h2 class="section-title-2">@childPage.title</h2>
                    <div class="table-responsive">
                        <table class="table table-hover custom-table">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>Product</th>
                                    <th>Qunatity</th>
                                    <th>Total</th>
                                </tr>
                            </thead>
                            <tbody>
    
                                @foreach (var itemInTable in childPage.Children){
                                    <tr>
                                        <td>@itemInTable.Count</td>
                                        <td class="text-primary">@itemInTable.tableItemName</td>
                                        <td>@itemInTable.tableItemAmount</td>
                                        <td>@itemInTable.tableItemTotal</td>
                                    </tr>
                                }
    
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </section>
    }
    

    So the itemInTable.Count should be the number.

    Kind regards, Robert

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Apr 03, 2015 @ 12:06
    Dave Woestenborghs
    101

    A simple solution would be doing this:

    @{
        var count = 1;
    }
    @foreach (var itemInTable in childPage.Children){
                                    <tr>
                                        <td>@cout</td>
                                        <td class="text-primary">@itemInTable.tableItemName</td>
                                        <td>@itemInTable.tableItemAmount</td>
                                        <td>@itemInTable.tableItemTotal</td>
                                    </tr>
                                    count++;
                                }

    Dave

  • Robert 63 posts 282 karma points
    Apr 03, 2015 @ 13:35
    Robert
    0

    Well that's looks easy indeed :D

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft