绑定Repeater控件的通用方法(包括分页事件)

 /// <summary>
        /// 分页方法
        /// </summary>
        /// <param name="ReSource">Repeater控件 </param>
        /// <param name="RePager">AspNetPager分布控件</param>
        /// <param name="PageIndex">当前页</param>
        /// <param name="strWhere">搜索条件</param>
        /// <param name="TableName">查询的表或视图</param>
        /// <param name="keyField">排序字段</param>
        public static void RepeaterBind(Repeater ReSource, AspNetPager RePager, int PageIndex, string strWhere, string TableName, string keyField)
        {
            int Acount = GetAllCount(strWhere, TableName);
            if (Acount > 0)
            {
                ReSource.Visible = true;
                RePager.Visible = true;
                ReSource.DataSource = GetList(PageIndex, strWhere, TableName, keyField);
                ReSource.DataBind();

                RePager.RecordCount = Acount;
                RePager.PageSize = PAGESIZE;

                #region 分页样式
                RePager.CustomInfoText = "共<font style=/"font-weight:bord;/"><b>&nbsp;" + RePager.RecordCount.ToString() + "&nbsp;</b></font>条数据";
                RePager.CustomInfoText += "&nbsp;&nbsp;总页数:<font style=/"font-weight:bord;/"><b>&nbsp;" + RePager.PageCount.ToString() + "&nbsp;</b></font>";
                RePager.CustomInfoText += "&nbsp;&nbsp;当前页:<font style=/"font-weight:bord;/"><b>" + RePager.CurrentPageIndex.ToString() + "</b></font>";
                #endregion
            }
            else
            {
                ReSource.Visible = false;
                RePager.Visible = false;
            }
        }

 

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        private static DataSet GetList(int PageIndex, string strWhere, string TableName, string keyId)
        {
            SqlParameter[] parameters = {
     new SqlParameter("@tblName", SqlDbType.VarChar, 255),
     new SqlParameter("@fldName", SqlDbType.VarChar, 255),
     new SqlParameter("@PageSize", SqlDbType.Int),
     new SqlParameter("@PageIndex", SqlDbType.Int),
     new SqlParameter("@IsReCount", SqlDbType.Bit),
     new SqlParameter("@OrderType", SqlDbType.Bit),
     new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
     };
            parameters[0].Value = TableName;
            parameters[1].Value = keyId;
            parameters[2].Value = PAGESIZE;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 1;//返回记录条数
            parameters[5].Value = 1;
            parameters[6].Value = strWhere;
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage", parameters, "ds");
        }

        private static int GetAllCount(string StrWhere, string TableName)
        {
            if (StrWhere.Trim() == "")
            {
                return Convert.ToInt32(DbHelperSQL.GetSingle("select count(1) from " + TableName));
            }
            else
            {
                return Convert.ToInt32(DbHelperSQL.GetSingle("select count(1) from " + TableName + " where " + StrWhere));
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值