How to use arrow in header for sorting in asp.net mvc
how to use arrow in header for sorting in asp.net mvc. if page is ascending then arrow to word below.if page is descending then arrow to word upword
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Suvendu Shekhar GiriRank #546 · 4.4K reputationPosted Nov 28, 2016, 11:48 PM EST
Suvendu Shekhar GiriRank #546 · 4.4K reputationPosted Nov 28, 2016, 11:49 PM EST
MayankRank #4,018 · 371 reputationPosted Nov 30, 2016, 12:55 AM EST
{
ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date";
List
var user = new DataModel
{
FirstMidName="A",
LastName= "A",
EnrollmentDate=DateTime.Now
};
var user2 = new DataModel
{
FirstMidName = "B",
LastName = "E",
EnrollmentDate = DateTime.Now
};
var user3 = new DataModel
{
FirstMidName = "C",
LastName = "D",
EnrollmentDate = DateTime.Now
};
students.Add(user);
students.Add(user2);
students.Add(user3);
switch (sortOrder)
{
case "name_desc":
students = students.OrderByDescending(s => s.LastName).ToList();
break;
case "Date":
students = students.OrderBy(s => s.EnrollmentDate).ToList();
break;
case "date_desc":
students = students.OrderByDescending(s => s.EnrollmentDate).ToList();
break;
default:
students = students.OrderBy(s => s.LastName).ToList();
break;
}
return View(students);
}
{
[Required]
public string Name { get; set; }
public string LastName { get; set; }
public string FirstMidName { get; set; }
public DateTime EnrollmentDate { get; set; }
}
@{
ViewBag.Title = "Sorting";
}
Sorting
@*@model PagedList.IPagedList
@using PagedList.Mvc;*@
@**@
@{
ViewBag.Title = "Students";
}
@*
@Html.ActionLink("Create New", "Create")
@using (Html.BeginForm("Index", "Student", FormMethod.Get))
{
Find by name: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
}*@
@Html.ActionLink("Last Name", "Sorting", new { sortOrder = ViewBag.NameSortParm })
First Name
Enrollment Date
@*@Html.ActionLink("Enrollment Date", "Sorting", new { sortOrder = ViewBag.DateSortParm })*@
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.LastName)
@Html.DisplayFor(modelItem => item.FirstMidName)
@Html.DisplayFor(modelItem => item.EnrollmentDate)
@*@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })*@
}
@*Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index",
new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))*@
Bikesh SrivastavaRank #108 · 20.3K reputationPosted Nov 30, 2016, 3:44 AM EST