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?