无为清净楼资源网 Design By www.qnjia.com
基本函数如下:
复制代码 代码如下:
/// <summary>
/// 需要分页时使用,根据参数和ConditionExpress获取DataTable
/// </summary>
/// <param name="_tableName">表名</param>
/// <param name="_fieldNames">字段名集合,用逗号分开</param>
/// <param name="_OrderColumn">排序字段,用于统计有多少条记录</param>
/// <param name="IsDesc">是否倒序</param>
/// <param name="_indexColumn">自增字段名</param>
/// <param name="_currentPage">当前页</param>
/// <param name="pageSize">页大小</param>
/// <param name="_rowsCount">总记录数</param>
/// <returns>获取到的DataTable</returns>
public static DataTable GetDataTable(string _tableName, string _fieldNames, string _OrderColumn, bool IsDesc, string _indexColumn, int _currentPage, int pageSize, string conditionExpress, ref int _rowsCount)
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
string whereStr = " where 1=1 ";
string sort = IsDesc ? " desc" : " asc";

string sqlStr = " from " + _tableName;
//排序字段
string orderStr = " order by " + _OrderColumn + sort;
if (_OrderColumn != _indexColumn)
orderStr += "," + _indexColumn + sort;
if (conditionExpress != string.Empty)
{
whereStr += conditionExpress;
}
sqlStr += whereStr;

//取得符合条件的数据总数
SqlCommand cmd = new SqlCommand("select count(" + _OrderColumn + ") " + sqlStr, conn);
conn.Open();
try
{
_rowsCount = (int)cmd.ExecuteScalar();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}

if (_currentPage > _rowsCount) _currentPage = _rowsCount;

if (_currentPage > 1)
{
if (IsDesc)
sqlStr += " and " + _OrderColumn + " < (select MIN(" + _OrderColumn + ") from ";
else
sqlStr += " and " + _OrderColumn + " > (select MAX(" + _OrderColumn + ") from ";
sqlStr += "(select top " + (pageSize * (_currentPage - 1)) + " " + _OrderColumn + " from " + _tableName + whereStr + orderStr + ") as t)";
}
sqlStr = "select top " + pageSize + " " + _fieldNames + sqlStr + orderStr;

try
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sqlStr, conn);
da.Fill(ds);
return ds.Tables[0];
}
catch (Exception EX)
{
throw new Exception(EX.Message);
}
}
}

调用如下:
复制代码 代码如下:
private void bind()
{
int rowCount = 1;
string wherestr = string.Empty;
//设置分页
anPager.AlwaysShow = true;
anPager.PageSize = 10;
this.rptdictionary.DataSource = GetDataTable(
"dictionary_Toysgogo_",
"[id_dictionary_],[namecn_dictionary_],[nameen_dictionary_],[point_dictionary_]",
"[id_dictionary_]",
true,
"[id_dictionary_]",
this.anPager.CurrentPageIndex,
anPager.PageSize,
wherestr,
ref rowCount
);
this.anPager.RecordCount = rowCount;
this.rptdictionary.DataBind();
}

复制代码 代码如下:
//分页切换
protected void anPager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
this.anPager.CurrentPageIndex = e.NewPageIndex;
this.tbxType.Text = this.tbxType.Text;
bind();
}

之前一直在页数方面直接用数字写进去,没有写成anPager.PageSize=10;的形式,在老汤的提醒下,做了修改,也解决了一直困扰我的问题。
标签:
asp.net,aspnetpager,分页

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。