+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Sorting by column name in Download List control (sorting problem)

Sorting by column name in Download List control (sorting problem)

5 posts, 0 answered
  1. Anders Olsen
    Anders Olsen avatar
    9 posts
    Registered:
    28 May 2010
    20 Oct 2010
    Link to this post
    I followed the instructions how to make "Sorting by column name in Download List control"
    http://www.sitefinity.com/devnet/kb/sitefinity-3-x/sorting-by-column-name-in-download-list-control.aspx

    It works, but always on the second click. Do you know what can be wrong??

    Example:
    My list is sorted ASC by default.. With following code (as in example):
            if (ViewState["SortOrder"] == null)
            {
    ViewState["SortOrder"] = " ASC";
            }
    My first click on the column link = ASC (data display), second = ASC, third = DESC

    If I change it for:
            if (ViewState["SortOrder"] == null)
            {
    ViewState["SortOrder"] = " DESC";
            }
    My first click on the column link  = ASC, second = DESC, third = ASC
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    20 Oct 2010
    Link to this post
    Hi Anders Olsen,

    Thank you for using our services.

    Can you try instead of putting those property values in the ViewState to expose a private field for the value and set this private field instead? So for example you will have
    private strign sortOrder = "ASC";

    which will be the default value.

    Kind regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Anders Olsen
    Anders Olsen avatar
    9 posts
    Registered:
    28 May 2010
    21 Oct 2010
    Link to this post
    I added the variable sortOrder as you adviced, but it is the same. First click (result = nothing), second click (result = ASC)

    I will describe once more with ViewState. First click the variable this.SortExpression = "Name ASC" (vissible result = nothing). Second click the variable this.SortExpression = "Name DESC" (vissible result = ASC). Third click the variable this.SortExpression = "Name ASC" (vissible result = DESC).

    I assume there is something wrong with Page Event order. 


    I attached my code. I use version 3.7.2096.2

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Engine;
     
    [System.ComponentModel.ToolboxItem(typeof(CustomDownloadListToolboxItem))]
    public class CustomDownloadList : Telerik.Libraries.DownloadList
    {
        public CustomDownloadList()
        {
     
        }
     
        protected override void SetItemHeaderContent(Control itemContainer, IContent contentItem)
        {
            base.SetItemHeaderContent(itemContainer, contentItem);
            LinkButton btn = itemContainer.FindControl("btnName") as LinkButton;
            if (btn != null)
            {
                btn.Command += new CommandEventHandler(btn_Command);
            }
     
        }
     
        void btn_Command(object sender, CommandEventArgs e)
        {
            this.SortData(e.CommandName);
             
        }
     
        void SortData(string sortExpression)
        {
            if (ViewState["SortOrder"] == null)
            {
                ViewState["SortOrder"] = " ASC";
            }
            else if (ViewState["SortOrder"].ToString() == " ASC")
            {
                ViewState["SortOrder"] = " DESC";
            }
            else
            {
                ViewState["SortOrder"] = " ASC";
            }
     
            this.SortExpression = sortExpression + ViewState["SortOrder"];
            this.ListContainer.RepeaterControl.DataBind();
     
        }
     
     
        public override string ItemListTemplatePath
        {
            get
            {
                return "~/Sitefinity/ControlTemplates/Libraries/CustomDownloadListTableModeTemplate.ascx";
            }
     
        }
     
        public override string SingleItemTemplatePath
        {
            get
            {
                return "~/Sitefinity/ControlTemplates/Libraries/CustomDownloadListTableModeTemplate.ascx";
            }
     
        }
     
        public override Type LocalizationAssemblyInfo
        {
            get
            {
                return this.GetType();
            }
            set
            {
                base.LocalizationAssemblyInfo = value;
            }
        }
     
        public override Type AssemblyInfo
        {
            get
            {
                return this.GetType();
            }
            set
            {
                base.AssemblyInfo = value;
            }
        }
     
    }
     
     
    public class CustomDownloadListToolboxItem : Telerik.Web.ToolboxItem
    {
     
        public CustomDownloadListToolboxItem()
            : base(typeof(CustomDownloadList))
        {
            base.DisplayName = "DisplayName";
            base.Description = "DownloadList_Description";
        }
    }

  4. Anders Olsen
    Anders Olsen avatar
    9 posts
    Registered:
    28 May 2010
    22 Oct 2010
    Link to this post
    Any idea what the problem is?
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Nov 2010
    Link to this post
    Hello Anders,

    Could you try to subscribe OnLoad to the Click event of your Button control and call this.RecreateChildControls(); after the sorting.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
5 posts, 0 answered