{
DataTable reuslt = new DataTable();
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
if (conn.State == ConnectionState.Closed)
conn.Open();
MySqlDataAdapter sda = new MySqlDataAdapter("CommonPagenation", conn);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
MySqlParameter[] param = new MySqlParameter[8];
param[0] = new MySqlParameter("?tableName", tableName);
param[1] = new MySqlParameter("?selectWhere", selectWhere);
param[2] = new MySqlParameter("?selectID", selectID);
param[3] = new MySqlParameter("?selectOrder", selectOrder);
param[4] = new MySqlParameter("?pageNo", pageNo);
param[5] = new MySqlParameter("?pageSize", pageSize);
param[6] = new MySqlParameter("?_totalcount",MySqlDbType.Int32);
param[6].Direction = ParameterDirection.Output;
param[7] = new MySqlParameter("?_pagecount", MySqlDbType.Int32);
param[7].Direction = ParameterDirection.Output;
sda.SelectCommand.Parameters.AddRange(param);
sda.Fill(reuslt);
totalcount = Convert.ToInt32(param[6].Value);
pagecount = Convert.ToInt32(param[7].Value);
}
return reuslt;
}
前台我是用的aspnetpager,非常好用的分页工具
<webdiyer:AspNetPager ID="ItemPaging" runat="server"
CustomInfoSectionWidth="30%" PageSize="20" FirstPageText="首页"
LastPageText="最后一页" NextPageText="下一页" PrevPageText="上一页"
ShowCustomInfoSection="Left" CenterCurrentPageButton="True" LayoutType="Table"
ShowPageIndexBox="Never" OnPageChanging="ItemPaging_PageChanging">
</webdiyer:AspNetPager>
调用::
DataTable table = DbHelperMySql.CommonPagenation("dede_archives", " typeid="+typeid, "", " dates desc ", ItemPaging.CurrentPageIndex, ItemPaging.PageSize,out totalcount,out pagecount);
ItemPaging.RecordCount = totalcount;
ItemPaging.AlwaysShow = true;
ItemPaging.CustomInfoHTML = "总计<font color='blue'><b>" + ItemPaging.RecordCount.ToString() + "</b></font>条,";
ItemPaging.CustomInfoHTML += "当前为第<font color='red'><b>" + ItemPaging.CurrentPageIndex.ToString() + "</b></font>页,";
ItemPaging.CustomInfoHTML += "共<font color='blue'><b>" + ItemPaging.PageCount.ToString() + "</b></font>页";