Sort values of a <li> by date C#

Asked

Viewed 60 times

0

Is it possible to sort the values of a dropdown per day? There is a order by or have to do really if’s for such?

Code example:

 <span class="dropdown">
    <button class="btn btn-search dropdown-toggle" type="button" id="horas" data-toggle="dropdown">
        <span id="newdisp">Nova disponibilidade</span><span class="caret" style="border-top:4px solid #FFF;"></span>
    </button>
    <ul class="dropdown-menu" role="menu" aria-labelledby="horas" onclick="newhour(event);">
        @{
            foreach (ScriptorContent horas in Model.Parts.Channel[0].Contents)
            {

                int empresa = (horas.Parts.titulo).LastIndexOf("- ");
                if (empresa > 0)
                {
                    string nome = (horas.Parts.titulo).Substring(empresa + 2);

                    if (nome == a.Parts.empresa[0].Parts.Name)
                    {
                        string horainicio = (horas.Parts.inicio).ToString("H:mm");
                        string horafim = (horas.Parts.fim).ToString("H:mm");
                        string data = (horas.Parts.inicio).ToString("dd/MM/yyyy");
                        <li role="presentation"><a role="menuitem" tabindex="-1">@data @horainicio - @horafim</a></li>
                    }
                }
            }
        }
    </ul>
</span>
  • 2

    you could use an order by on your foreach, it would be something like foreach (ScriptorContent horas in Model.Parts.Channel[0].Contents.OrderBy(a=>a.Campo)), If it works out, let me know and I’ll put in an answer

  • @Pablovargas is correct. Put as answers, if there is a problem, you can edit your answer.

  • I did it differently. I made a queryContents and after that query, I did the orderby, but it wasn’t with lambda Expressions, I did like this: Orderby("$$.title asc") Thanks for your answers.

1 answer

1

a solution to your problem, would be to use a OrderBy in his foreach, being like this:

foreach (ScriptorContent horas in Model.Parts.Channel[0].Contents.OrderBy(a=>a.Campo))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.