Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Location
    Detroit
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to order by date

    Hello,

    I am not a developer or programmer. I was asked to change some code so that events on an event page would load by date order. The code is below. What would I add/change? Thanks in advance!

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Collections.Generic;
    using System.Linq;

    public partial class Events : System.Web.UI.Page
    {
    #region Data

    public struct DisplayItem
    {
    private string _EventDate;
    public string _EventName;
    public long _EventId;

    public string EventDate
    {
    get { return _EventDate; }
    set { _EventDate = value; }
    }

    public string EventName
    {
    get { return _EventName; }
    set { _EventName = value; }
    }

    public long EventId
    {
    get { return _EventId; }
    set { _EventId = value; }
    }
    }

    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
    string pageTitle = string.Empty;
    long folderId = 0;
    long CalendarID = 0;
    string CalendarIdString = string.Empty;
    bool showEvent;

    //Get the CalendarID from the Query String
    if (Request.QueryString.HasKeys())
    {
    if (!string.IsNullOrEmpty(Request.QueryString["CalendarId"]))
    {
    CalendarIdString = Request.QueryString["CalendarId"];
    long.TryParse(CalendarIdString, out CalendarID);
    }
    }

    //Seminars
    if (CalendarID == 164)
    {
    pageTitle = "Free Seminars";
    folderId = 132;
    showEvent = false;
    }
    else //default
    {
    CalendarID = 172;
    pageTitle = "Events";
    folderId = 138;
    showEvent = true;
    }

    CalendarID = 172;

    MFCU.MFCU_Utilities.SetBreadCrumb(this, folderId);
    this.litTitle.Text = pageTitle;
    this.Title = pageTitle;

    if (!this.IsPostBack)
    {
    this.LoadData(showEvent, CalendarID);
    }
    }

    private void LoadData(bool showEvent, long calendarID)
    {
    List<DisplayItem> displayList = new List<DisplayItem>();
    Ektron.Cms.Framework.Calendar.WebEvent calendarEvent = new Ektron.Cms.Framework.Calendar.WebEvent();
    List<Ektron.Cms.Common.Calendar.WebEventData> listData;
    listData = calendarEvent.GetEventOccurrenceList(calendarID, DateTime.Now, DateTime.Now.AddDays(60));
    Ektron.Cms.API.Metadata mApi = new Ektron.Cms.API.Metadata();


    listData.Reverse();

    foreach (Ektron.Cms.Common.Calendar.WebEventData item in listData)
    {
    string freeSeminar = mApi.GetContentMetadataList(item.Id).GetItemByName("FreeSeminar").Value.ToString();
    bool isFreeSeminar;

    //Show Free seminars
    if (!showEvent && freeSeminar.ToLower() == "no")
    {
    continue;
    }

    //Show events
    if (showEvent && freeSeminar.ToLower() == "yes")
    {
    //continue;
    }

    DisplayItem dataItem = new DisplayItem();
    dataItem.EventDate = item.EventStart.ToString("MMMM d h:mm tt");
    dataItem.EventName = item.DisplayTitle;
    dataItem.EventId = item.Id;
    displayList.Add(dataItem);
    }

    this.Repeater1.DataSource = displayList;
    this.Repeater1.DataBind();
    }

    }

  • #2
    New Coder
    Join Date
    Aug 2011
    Posts
    50
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Sort Date

    It involves implementing the icomparer class.

    Take this sample as Example:

    Code:
    Public Class DataGridViewSortRowsByDateTime
            Implements System.Collections.IComparer
            Private Direction As Integer = 1
            Public Sub New(ByVal so As SortOrder)
                If so = SortOrder.Descending Then
                    Direction = -1
                ElseIf so = SortOrder.Ascending Then
                    Direction = 1
                End If
            End Sub
            Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
            Implements System.Collections.IComparer.Compare
                Dim RowOne As DataGridViewRow = CType(x, DataGridViewRow)
                Dim RowTwo As DataGridViewRow = CType(y, DataGridViewRow)
                Dim Result As Integer = _
                System.DateTime.Compare(RowOne.Cells(0).Value, RowTwo.Cells(0).Value)
                Return Result * Direction
            End Function
        End Class
    For Ascending Sort use this line:

    Code:
    DataGridView1.Sort(New DataGridViewSortRowsByDateTime(SortOrder.Ascending))
    For Descending Sort use this line:

    Code:
    DataGridView1.Sort(New DataGridViewSortRowsByDateTime(SortOrder.Descending))


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •