Copied to clipboard

Flag this post as spam?

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


  • Lex Godthelp 15 posts 99 karma points
    Aug 24, 2017 @ 10:09
    Lex Godthelp
    0

    Displaying items in a different column depending on position

    Hi Guys,

    I was wondering if there was any quick way to do the following:

    @foreach(first item and every third item after position 1)
    <div class="col-md-4">
        <div class="item-container">
            <h2>@item.Header</h2>
        </div>
    </div>}
    
    @foreach(second position item and third item after position 2){
    <div class="col-md-4">
        <div class="item-container">
            <h2>@item.Header</h2>
        </div>
    </div>}
    @foreach(third position item and third item after position 3){
    <div class="col-md-4">
        <div class="item-container">
            <h2>@item.Header</h2>
        </div>
    </div>}
    

    With the output:

    <div class="col-md-4">
    <div class="item-container">
        <h2>#item1</h2>
        <h2>#item4</h2>
        <h2>#item7</h2>
        etc.
    </div>
    

    <div class="col-md-4">
    <div class="item-container">
        <h2>#item2</h2>
        <h2>#item5</h2>
        <h2>#item8</h2>
        etc.
    </div>
    

    <div class="col-md-4">
    <div class="item-container">
        <h2>#item3</h2>
        <h2>#item6</h2>
        <h2>#item9</h2>
        etc.
    </div>
    

    This isn't really something I can do with i % 4 or with position() mod 3 right?

  • Manish 373 posts 932 karma points
    Aug 24, 2017 @ 11:23
    Manish
    0

    Can you please explain your problem in more detail would be good by diagram

  • Lex Godthelp 15 posts 99 karma points
    Aug 24, 2017 @ 11:37
    Lex Godthelp
    0

    Hello Manish,

    See the attached image. I hope that helps.

    enter image description here

  • Manish 373 posts 932 karma points
    Aug 24, 2017 @ 12:05
    Manish
    0

    Create three list something like this

    List<int> term1 = new List<int>();
    List<int> term2 = new List<int>();
    List<int> term3 = new List<int>();
    
    for(i=0; i<arr.length;i+=3){
    term1.add(arr[i]);
    term2.add(arr[i+1]);
    term3.add(arr[i+2]);
    

    }

  • Manish 373 posts 932 karma points
    Aug 24, 2017 @ 12:27
    Manish
    100
       List<int> mainArr = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
            List<int> sub1 = new List<int>();
            List<int> sub2 = new List<int>();
            List<int> sub3 = new List<int>();
            int i;
            for (i = 0; i < mainArr.Count; i += 3)
            {
    
                sub1.Add(mainArr[i]);
                if (i+1 < mainArr.Count)
                {
                    sub2.Add(mainArr[i + 1]);           
                }
                if (i+2 < mainArr.Count)
                {
                    sub3.Add(mainArr[i + 2]);          
                }
    
    
            }
    
  • Lex Godthelp 15 posts 99 karma points
    Aug 24, 2017 @ 12:29
    Lex Godthelp
    1

    Thanks Manish,

    I'll go and try it and get back to you!

Please Sign in or register to post replies

Write your reply to:

Draft