WinFrom paging with GridControl and DataNavigtor in Devexpress in

1, page Well you have to have a SQL program in order to write down the first offer at the idea of ​​SQL, SQL for paging post has introduced me before, not introduced

SELECT  Top the pageSize *      - shows the number
 from ( SELECT ROW_NUMBER ()   
 over ( Order  by EG_ID ASC ) AS RowNumber, * - number of rows
 from ExchangGifts) temp_row
 WHERE RowNumber > ((the pageIndex - . 1 ) * the pageSize); - start page number - recommended SQL

Refer to the stored procedure

CREATE proc [dbo].[P_GetCardLevelsPaged]
    @PageSize int,
    @PageIndex int,
    @Count int output,
    @LevelName varchar(20)
as
begin
    select top(@PageSize) * from CardLevels 
    where CL_ID not in(
                        select top(@PageSize*(@PageIndex-1)) CL_ID from CardLevels where CL_LevelName like '%'+@LevelName+'%'
                      ) 
    and CL_LevelName like '%'+@LevelName+'%'
    select @Count=COUNT(*) from CardLevels where CL_LevelName like '%'+@LevelName+'%'
end

GO

2, an example of using the tab SQL:

SELECT * FROM(SELECT ROW_NUMBER() OVER(order BY E.EG_ID) as rows ,E. * FROM ExchangGifts E)
 AS A WHERE A.rows BETWEEN 1 and 10;   

 

 

Detailed code comments

 public partial class XtraForm2 : DevExpress.XtraEditors.XtraForm
    {

        Private  int the pageIndex = . 1 ; // current page 
        Private  int the pageSize = . 5 ;    // page of size 
        Private  int , pageCount = 0 ; // total number of pages
      
       public XtraForm2()
        {
            InitializeComponent();
        }

  // get record total 
        public  int GetRecordCount ()
        {
            int count = 0;
            string sql = "select count(*) from ExchangGifts";
            count = Convert.ToInt32(DBHelper.GetScalar(sql, null, false));
            return count;
        }

        // get list of records of the current page 
        public DataTable GetListByPage ( int startIndex, int endIndex)
        {
            DataTable dt = new DataTable();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from (");
            strSql.Append("select row_number() over(order by t.[EG_ID]) as rows,t.* from ExchangGifts as t) as tt");
            strSql.AppendFormat(" where tt.rows between {0} and {1} ", startIndex, endIndex);
            dt = DBHelper.Query(strSql.ToString(), null);
            return dt;
        }

        // Bind data grid control 
        public  void BindPageGridList ()
        {
            // start index record 
            int startIndex = (the pageIndex - . 1 ) * the pageSize + . 1 ;
             // End index record 
            int endIndex * = the pageIndex the pageSize;
             // total number of records 
            int Row = GetRecordCount ();

            if (row % pageSize > 0)
            {
                pageCount = row / pageSize + 1;
            }
            else
            {
                pageCount = row / pageSize;
            }
            // If the current is the last page, set the record of the last line of the index 
            IF (pageIndex == pageCount)
            {
                endIndex = row;
            }

            DataTable dt = this.GetListByPage(startIndex, endIndex);
            gc.DataSource = dt;
            nvgDataPager.DataSource = dt;
            nvgDataPager.TextStringFormat = String .Format ( " {0} of {1} " , the pageIndex,, pageCount);
        }

        private void nvgDataPager_ButtonClick(object sender, NavigatorButtonClickEventArgs e)
        {
            string type = e.Button.Tag.ToString();
            switch (type)
            {
                Case  " Home " :
                    pageIndex = 1;
                    break;
                case "末页":
                    pageIndex = pageCount;
                    break;
                case "下一页":
                    if (pageIndex < pageCount)
                    {
                        pageIndex++;
                    }
                    BREAK ;
                 Case  " Previous " :
                     IF (the pageIndex> . 1 )
                    {
                        pageIndex--;
                    }
                    break;
            }
            the this .BindPageGridList (); // bind the control to the current page 
        }

}

Renderings

 

Guess you like

Origin www.cnblogs.com/yijieyufu/p/12306088.html