DataTable data paging

When the need to show some data, if the data more, then you need to use tabs to show, so as not to seem burdensome page.

Therefore, a data acquisition method DataTable paged in this record:

        ///  <Summary> 
        /// the Select Data page tab
         ///  </ Summary> 
        ///  <param name = "dt"> Data Source </ param> 
        ///  <param name = "the PageIndex"> first few p </ param> 
        ///  <param name = "the PageSize"> per how many </ param> 
        ///  <Returns> </ Returns> 
        public  static the DataTable getPageToDataTable (the DataTable dt, int the PageIndex, int the PageSize) 
        { 
            IF (the PageIndex == 0 )
                 return dt;// 0 on behalf of each page of data, direct return 

            IF (dt == null) 
            { 
                The DataTable Table = new new the DataTable ();
                 return Table; 
            } 

            the DataTable newdt = dt.Copy (); 
            newdt.Clear (); // a frame of the copy dt 

            int rowbegin = (the PageIndex - . 1 ) * the PageSize;
             int rowend = the PageIndex the PageSize *; // to show the number of stripes 

            IF (rowbegin> = dt.Rows.Count)
                 return newdt; // source of data records less than or equal to display records directly back dt 

            IF (rowend>  dt.Rows.Count )
                rowend= dt.Rows.Count;
            for (int i = rowbegin; i <= rowend - 1; i++)
            {
                DataRow newdr = newdt.NewRow();
                DataRow dr = dt.Rows[i];
                foreach (DataColumn column in dt.Columns)
                {
                    newdr[column.ColumnName] = dr[column.ColumnName];
                }
                newdt.Rows.Add(newdr);
            }
            return newdt;
        }

The above code is already in use on the datatable check out the data, and then filter data to datatable.

 

Guess you like

Origin www.cnblogs.com/yanwu/p/11103034.html