Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6986505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:49:03+00:00 2026-05-27T18:49:03+00:00

I am trying to do a sort here to display the latest entries first.

  • 0

I am trying to do a sort here to display the latest entries first. I have a repeater control which is bound to a pagedDataSource, and my sorting only works for page wise rather than the whole collection itself.

here is my code behind :

    private int RowCount
    {
        get
        {
            return (int)ViewState["RowCount"];
        }
        set
        {
            ViewState["RowCount"] = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            FetchData(5, 0);                    
        }
        else
        {
            plcPaging.Controls.Clear();
            CreatePagingControl();
        }

    }

    private void FetchData(int take, int pageSize)
    {
        using (krystaladbDataContext db = new krystaladbDataContext())
        {
            var query = from q in db.question_tables

                        .Take(take)
                        .Skip(pageSize)

                        orderby q.QUEST_POSTED_DATE descending
                        select new
                        {


                            QUEST_ID = q.QUEST_ID,
                            QUEST_TEXT = q.QUEST_TEXT,
                            QUEST_POSTED_DATE = q.QUEST_POSTED_DATE,
                            QUEST_USR_ID = q.QUEST_USR_ID,
                            QUEST_LIKES_COUNT = q.QUEST_LIKES_COUNT,
                            QUEST_REPORT_COUNT = q.QUEST_REPORT_COUNT,
                            Count = db.question_tables.Count()

                        };




            PagedDataSource page = new PagedDataSource();
            page.AllowCustomPaging = true;
            page.AllowPaging = true;
            page.DataSource = query;
            page.PageSize = 5;
            QRep.DataSource = page;
            QRep.DataBind();

            if (!IsPostBack)
            {
                RowCount = query.First().Count;
                CreatePagingControl();

            }
        }
    }

    private void CreatePagingControl()
    {
        for (int i = 0; i < (RowCount / 5) + 1; i++)
        {
            LinkButton lnk = new LinkButton();
            lnk.Click += new EventHandler(lbl_Click);
            lnk.ID = "lnkPage" + (i + 1).ToString();
            lnk.Text = (i + 1).ToString();
            plcPaging.Controls.Add(lnk);
            Label spacer = new Label();
            spacer.Text = "&nbsp;";
            plcPaging.Controls.Add(spacer);
        }

    }

EDIT:: included the page control event handler

    void lbl_Click(object sender, EventArgs e)
    {
        LinkButton lnk = sender as LinkButton;
        int currentPage = int.Parse(lnk.Text);
        int take = currentPage * 5;
        int skip = currentPage == 1 ? 0 : take - 5;
        FetchData(take, skip);
    }

What I want is basically to have the sort work across all the pages rather than for just one page. Please point me in the right direction guys. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:49:04+00:00Added an answer on May 27, 2026 at 6:49 pm

    Do the order by before the take.

    var query = from q in db.question_tables
                orderby q.QUEST_POSTED_DATE descending
                select new
                {
                  QUEST_ID = q.QUEST_ID,
                  QUEST_TEXT = q.QUEST_TEXT,
                  QUEST_POSTED_DATE = q.QUEST_POSTED_DATE,
                  QUEST_USR_ID = q.QUEST_USR_ID,
                  QUEST_LIKES_COUNT = q.QUEST_LIKES_COUNT,
                  QUEST_REPORT_COUNT = q.QUEST_REPORT_COUNT,
                  Count = db.question_tables.Count()
                 }
                 .Take(take)
                 .Skip(pageSize);
    

    You could alternatively use the linq .OrderBy method before the .Take

    Then on the paging control.

    void lbl_Click(object sender, EventArgs e)
    {
        LinkButton lnk = sender as LinkButton;
        int currentPage = int.Parse(lnk.Text);
        int take = page.PageSize;
        int skip = page.PageSize * (currentPage - 1); 
        FetchData(take, skip);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create sort of a lifestream, in which I would display tweets
I am trying to display a list of cookbooks which have been tagged with
Here is my view. I am trying to simply display a table with the
Pretty sure that I'm missing something really simple here: I'm trying to display a
Please have a quick read of this question first: Separating a list of entries
hiya i have a massive job trying to sort thousands of records all is
I'm trying to figure out how to sort the first 10 Markers on a
Here's what I'm trying to do: I have a list of Faculties, within each
Here's the problem I'm trying to solve: I need to be able to display
Trying to sort this array of objects according to (1) depth and (2) weight,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.