protected void gvTestimonials_Sorting(object sender, GridViewSortEventArgs e) { TestimonialSortingType orderBy = TestimonialSortingType.IdAsc; switch (e.SortExpression) { case "Name": orderBy = TestimonialSortingType.NameDesc; if (e.SortDirection == SortDirection.Ascending) { orderBy = TestimonialSortingType.NameAsc; } break; case "Comment": orderBy = TestimonialSortingType.CommentDesc; if (e.SortDirection == SortDirection.Ascending) { orderBy = TestimonialSortingType.CommentAsc; } break; case "Id": default: orderBy = TestimonialSortingType.IdDesc; if (e.SortDirection == SortDirection.Ascending) { orderBy = TestimonialSortingType.IdAsc; } break; } SetState("OrderBy", (int)orderBy); LoadTestimonials(); }
public PagedList <Testimonial> GetTestimonialLoadPaged( int pageIndex = 0, int pageSize = 2147483647, string comment = null, string name = null, TestimonialSortingType orderBy = TestimonialSortingType.IdAsc) { var query = _testimonialRepository.Table; if (!string.IsNullOrEmpty(comment)) { query = query.Where(x => x.Comment.Contains(comment)); } if (!string.IsNullOrEmpty(name)) { query = query.Where(x => x.Name.Contains(name)); } int totalRecords = query.Count(); switch (orderBy) { default: case TestimonialSortingType.IdAsc: query = query.OrderBy(x => x.Id); break; case TestimonialSortingType.IdDesc: query = query.OrderByDescending(x => x.Id); break; case TestimonialSortingType.NameAsc: query = query.OrderBy(x => x.Name); break; case TestimonialSortingType.NameDesc: query = query.OrderByDescending(x => x.Name); break; case TestimonialSortingType.CommentAsc: query = query.OrderBy(x => x.Comment); break; case TestimonialSortingType.CommentDesc: query = query.OrderByDescending(x => x.Comment); break; } query = query.Skip(pageIndex * pageSize).Take(pageSize); var list = query.ToList(); return(new PagedList <Testimonial>(list, pageIndex, pageSize, totalRecords)); }
private void LoadTestimonials() { string comment = null; string name = null; TestimonialSortingType orderBy = TestimonialSortingType.IdAsc; if (HasState(COMMENT_FILTER)) { comment = GetStringState(COMMENT_FILTER); } if (HasState(NAME_FILTER)) { name = GetStringState(NAME_FILTER); } if (HasState("OrderBy")) { orderBy = (TestimonialSortingType)GetIntState("OrderBy"); } var result = UtilityService.GetTestimonialLoadPaged( pageIndex: gvTestimonials.CustomPageIndex, pageSize: gvTestimonials.PageSize, comment: comment, name: name, orderBy: orderBy); if (result != null) { gvTestimonials.DataSource = result.Items; gvTestimonials.RecordCount = result.TotalCount; gvTestimonials.CustomPageCount = result.TotalPages; } gvTestimonials.DataBind(); if (gvTestimonials.Rows.Count <= 0) { enbNotice.Message = "No records found."; } }