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 6872039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:52:41+00:00 2026-05-27T03:52:41+00:00

I don’t understand how you can only get the number of needed rows from

  • 0

I don’t understand how you can only get the number of needed rows from a database when you need to know the total amount of rows inorder to get paging to work.

What I mean is:
I followed this example:
http://www.c-sharpcorner.com/uploadfile/rizwan328/datalist-custom-paging-in-Asp-Net-using-C-Sharp/

But instead of using a dataTable I have a database.

I get the news from the database like this, this gets all the news from my news table:

List<News> news = News.GetNews();

public static List<News> GetNews(){
    List<News> news = new List<News>();
    using (SqlConnection conn = new SqlConnection(CONNSTRING)) {
            SqlCommand cmd = new SqlCommand("SELECT * FROM News_news ORDER BY date DESC", conn);

That gets all the data from all the news items.

Then I create a PagedDataSource:

PagedDataSource objPds = new PagedDataSource();
objPds.DataSource = news;
objPds.AllowPaging = true;
objPds.PageSize = numRows;
//Set the current page 
objPds.CurrentPageIndex = CurrentPage;

//Set the buttons

Putt the data in a repeater that will show the first 5 items on the aspx page

repeater1.DataSource = objPds;
repeater1.DataBind(); 

Like this I have a paged front page that shows me the total number of pages and the current page and when I click on the button for the next page I do it all over again.

But I know this isn’t correct since I always get all the news and then discared the news I don’t need. but please, how do need to do it so that I only get the needed news items?

Do I need to first count the number of rows in my table?

  • 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-27T03:52:41+00:00Added an answer on May 27, 2026 at 3:52 am

    To use PagedDataSource, all records will be returned during the query, but you can use persistent data storage (Session and ViewState) to store the data set so that each page request does not have to hit the database again.

    If you want to only ever pull back the records for the page you are viewing, as far as I know you will have to roll your own paging solution. I ran in to the need for my own paging solution a while back, and here is a SO question I asked that helped me do what I needed, Paging choice, on database or in the web application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know why I can't reply to people on here with only a small
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't know where else to ask, but from one day to the other my
Don't know why this doesn't work. I can't do implicit animation for a newly
Don't know is it possible to copy elements from one map to another map
Don't know if it matters, but the msg.d is about 300 rows long. I
Don't ask me why but i can't use this method because I need to
Don't know why but I can't find a solution to this. I have 3
Don't know if anyone can help me with this or if it's even possible.
Don't know how to explain it better but i'm trying to get a response

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.