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

Forums / Developing with Sitefinity / Sorting in NewsView Control

Sorting in NewsView Control

5 posts, 0 answered
  1. Phani
    Phani avatar
    7 posts
    Registered:
    22 Apr 2009
    17 Aug 2009
    Link to this post
    I have a requirement for sorting items in newsview control based on Title & Descending. The User selects the criteria from the combo. The UI is as shown in the attached image.
    Once the user selects the item from the combo the onselectionchanged event i am assigning SortExpression of the newsview control and rebind the control.

    In the markup of the newsview Control template i have added a combobox

    <telerik:RadComboBox ID="ddlSort" runat="server" AllowCustomText="true" EmptyMessage="Sort news by..." AutoPostBack="true"></telerik:RadComboBox> 


    So in the codebehind of the control template for newsview control i have written the following code



    protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.IsPostBack) 
            { 
                ddlSort.Items.Add(new RadComboBoxItem("Title Ascending", "Title Asc")); 
                ddlSort.Items.Add(new RadComboBoxItem("Title Descending", "Title Desc")); 
                ddlSort.Items.Add(new RadComboBoxItem("Date Descending", "Publication_Date Desc")); 
                ddlSort.Items.Add(new RadComboBoxItem("Date Ascending", "Publication_Date Asc")); 
            } 
        
            ddlSort.SelectedIndexChanged += new Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventHandler(ddlSort_SelectedIndexChanged); 
        } 
     
    void ddlSort_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e) 
        { 
            NewsView newsView = (NewsView)this.Parent.Parent; 
            newsView.SortExpression = e.Value; 
            newsView.DataBind(); 
        } 

    But with this code the Current selected Sort expression is applied in the next postback.That is Data is bound before the SortExpression is assigned.

    Can you suggest me a solution for this problem.

    I am using Sitefinity 3.6 SP2
  2. Parvan
    Parvan avatar
    151 posts
    Registered:
    24 Sep 2012
    18 Aug 2009
    Link to this post
    Hello Phani,

    Thank you for using our services.

    Please consider the following code:

        private string selectedValue; 
         
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!Page.IsPostBack || ddlSort.Items.Count <= 1) 
            { 
                NewsView newsView = (NewsView)this.Parent.Parent; 
                selectedValue = newsView.SortExpression; 
                ddlSort.Items.Add(new RadComboBoxItem("Title Ascending""Title Asc")); 
                ddlSort.Items.Add(new RadComboBoxItem("Title Descending""Title Desc")); 
                ddlSort.Items.Add(new RadComboBoxItem("Date Descending""Publication_Date Desc")); 
                ddlSort.Items.Add(new RadComboBoxItem("Date Ascending""Publication_Date Asc")); 
                ddlSort.SelectedValue = selectedValue; 
            } 
     
            ddlSort.SelectedIndexChanged += new Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventHandler(ddlSort_SelectedIndexChanged); 
        } 
     
        void ddlSort_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e) 
        { 
            NewsView newsView = (NewsView)this.Parent.Parent; 
            selectedValue = e.Value; 
            newsView.SortExpression = e.Value; 
            newsView.FilterExpression = "#filter"
            string test = newsView.FilterExpression; 
        } 
     
        protected override void OnPreRender(EventArgs e) 
        { 
            base.OnPreRender(e); 
            if (!string.IsNullOrEmpty(selectedValue) && ddlSort.Items.Count <= 1) 
            { 
                ddlSort.Items.Add(new RadComboBoxItem("Title Ascending""Title Asc")); 
                ddlSort.Items.Add(new RadComboBoxItem("Title Descending""Title Desc")); 
                ddlSort.Items.Add(new RadComboBoxItem("Date Descending""Publication_Date Desc")); 
                ddlSort.Items.Add(new RadComboBoxItem("Date Ascending""Publication_Date Asc")); 
                ddlSort.SelectedValue = selectedValue; 
            } 
        } 


    I hope this helps you.

    Sincerely yours,
    Parvan
    the Telerik team

    Instantly find answers to your questions on the newTelerik Support Portal.
    Check out the tipsfor optimizing your support resource searches.
  3. Phani
    Phani avatar
    7 posts
    Registered:
    22 Apr 2009
    19 Aug 2009
    Link to this post
    Thank you, It worked for me
  4. Patrick D
    Patrick D avatar
    4 posts
    Registered:
    20 Aug 2009
    21 Sep 2009
    Link to this post
    I'm attempting to do something similar with version 3.7. Did you modify the /Sitefinity/ControlTemplates/ListPageMaster.ascx?  Seems as though any changes I make to this file are NOT reflected when the page renders!?!? 
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    21 Sep 2009
    Link to this post
    Hi Patrick D,

    Please make sure that the template you use has been mapped. You can gather more information about mapping templates for ContentView based controls at Working with presentation modes.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
5 posts, 0 answered