Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 11th, 2004, 11:16 PM
Authorized User
Join Date: Aug 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Limit rows returned and next rows

I use C#.NET

I have sql statement. This sql statement return too many rows.

The firstly show, I want to show 20 rows on my .aspx web page.

When I click "Next page 20 items" label, then return next 20 items and repeat until no rows.

When I click "Previous page 20 items" then return previous 20 items and repeat until first 20 rows.

How did I do that?

Thank you so much.

Best regards,

Minh Phan.

Old August 12th, 2004, 06:25 AM
Friend of Wrox
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi

If you are using datagrid to display the records then Set the Paging & CustomPaging property of the DataGrid to true and pagesize to 20.

See the sample below:

private void Page_Load(object sender, System.EventArgs e)
{ // Put user code to initialize the page here
private void BindGrid(int st,int nt){
    string sqlconn;
    string strSql;
     SqlConnection conn=new SqlConnection(sqlconn);
    strSql="select job_id,job_desc,min_lvl,max_lvl from jobs where job_id>="+st+" and job_id<="+nt+"";
        SqlDataAdapter strAdap=new SqlDataAdapter(strSql,conn);
    DataSet ds=new DataSet();
private void InitializeComponent()
    this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEvent Handler(this.DataGrid1_PageIndexChanged);
     this.Load += new System.EventHandler(this.Page_Load);
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
   DataGrid1.CurrentPageIndex = e.NewPageIndex;
   BindGrid((e.NewPageIndex *DataGrid1.PageSize)+1,(e.NewPageIndex* DataGrid1.PageSize)+DataGrid1.PageSize);

Here BindGrid() function is used to bind the data's to the datagrid and VirtualItemCount property allows the control to determine the total number of pages needed to display every item in the DataGrid control.

Similar Threads
Thread Thread Starter Forum Replies Last Post
column to rows mitasid Beginning VB 6 1 June 12th, 2006 01:37 PM
selecting rows returned by executing a SP dsekar_nat SQL Server 2000 4 May 11th, 2006 11:12 AM
Outputto exceeded limit of rows Renee Voice Access VBA 2 February 26th, 2006 04:47 PM
duplicate rows msrnivas Classic ASP Components 1 August 26th, 2004 02:07 AM
limit rows returned in a list box stoneman Access 1 January 16th, 2004 10:46 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.