分页中的页数问题

public static int GetCountByTableName(string tableName)
        {
            return shuju_Access.GetCount(string.Format("select Count(*) from {0} datatable", tableName));
        }

      public static int GetCount(string cmdText, params SqlParameter[] prams)
        {
            using (SqlConnection connection = new SqlConnection())
            {
                SqlCommand cmd = new SqlCommand();
                CreateCommand(connection, cmd, cmdText, prams);
                int num = 0;
                object obj2 = cmd.ExecuteScalar();
                if (obj2 == null)
                {
                    num = 0;
                }
                else
                {
                    num = Convert.ToInt32(obj2);
                }
                cmd.Parameters.Clear();
                return num;
            }
        }

 public static int GettTotalpage(string cmdtext, int pagesize)
        {

            return GettTotalpage(cmdtext, pagesize, null);
        }

 public static int GettTotalpage(string cmdtext, int pagesize, params SqlParameter[] prams)
        {
            int totalpages = 0;
            int totalnums = 0;
            totalnums = GetCount(cmdtext, prams);
            if (totalnums <= 0)
            {

                totalpages = 0;

            }
            if (totalnums > 0)
            {
                float ss = totalnums / pagesize;
                if (totalnums % pagesize == 0)
                {
                    totalpages = int.Parse(System.Math.Ceiling(ss).ToString());
                }
                else
                {
                    totalpages = int.Parse(System.Math.Ceiling(ss).ToString())+1;
               
                }

            }

            return totalpages;
        }

=========1、是需要注意的是关于得到总条数的时候需要用到的是:count(*)

=========2、是计算页数的是否,需要的是看什么是否加1.

你可能感兴趣的:(Web,分页)