关于asp.net中分页控件的应用,引用dll文件
前台控件:
<webdiyer:AspNetPager ID="aspPageRange" runat="server"
HorizontalAlign="left"
PageSize="2"
CssClass="pages" CurrentPageButtonClass="cpb" FirstPageText="首页"
LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页"
ShowBoxThreshold="11" TextAfterInputBox="" AlwaysShow="true"
TextBeforeInputBox="" onpagechanged="aspPageRange_PageChanged"
SubmitButtonStyle="width:30px">
</webdiyer:AspNetPager>
后台代码:
dll.GetList(entity, this.aspPageRange.CurrentPageIndex, this.aspPageRange.PageSize, out total);
三层中的DLL类中的方法:
public static DataSet GetListByUserTypeAndRangeType(DeviceBreakdown deviceBreakdown, int RangeType, int pageIndex, int pageSize, out int recordCount)
{
DataSet dsResult = null;
recordCount = 0;
DataAccessBase dataAccess = DataAccessFactory.GetDataAccess();
try
{
BindParams(ref dataAccess, ref deviceBreakdown);
dataAccess.AddParam("RanggeType", RangeType);
dataAccess.AddParam("PageIndex", pageIndex);
dataAccess.AddParam("PageSize", pageSize);
dataAccess.AddParam("PageTotal", recordCount, ParameterDirection.Output);
dataAccess.AddParam("ActionType", 13);
dsResult = dataAccess.ExecuteDataSet("P_DeviceBreakdown", CommandType.StoredProcedure);
recordCount = (int)dataAccess.GetCommandParam("PageTotal").Value;
}
catch (Exception ex) { throw ex; }
finally { dataAccess.CompletedCommand(); }
return dsResult;
}
添加参数即可.
SQL中的存储过程
SELECT * FROM
(
SELECT *,ROW_NUMBER() over(order by DeclaredOn desc) AS rn FROM
(
SELECT T_DeviceBreakdown.*,(select datediff(HOUR,T_DeviceBreakdown.DeclaredOn,getdate())) as tt,(case when T_DeviceMaintainBill.Id IS null then 0 else 1 end) as WeiXiu
FROM T_DeviceBreakdown left join T_DeviceMaintainBill
on T_DeviceMaintainBill.[DBId] = T_DeviceBreakdown.Id
) nt
WHERE (MaintainAlarm= @MaintainAlarm or @MaintainAlarm is null) --是否确认
and (nt.WeiXiu = @RanggeType or @RanggeType is null) --是否维修
and (BreakdownLevel = @BreakdownLevel or @BreakdownLevel is null) --故障等级
and (cast(convert(varchar,DeclaredOn,112) as smalldatetime) = @DeclaredOn or @DeclaredOn is null)--申报时间
AND (nt.MaintainUserId=@MaintainUserId or @MaintainUserId is null) --登录人 角色
and (WId =@WId or @WId is null) --仓库
) nnt
WHERE nnt.rn between (isnull(@PageIndex,0) - 1)*@PageSize+1 and @PageIndex*@PageSize;
SELECT @PageTotal= COUNT(Id) FROM
(
SELECT T_DeviceBreakdown.*,(select datediff(HOUR,T_DeviceBreakdown.DeclaredOn,getdate())) as tt,(case when T_DeviceMaintainBill.Id IS null then 0 else 1 end) as WeiXiu
FROM T_DeviceBreakdown left join T_DeviceMaintainBill
on T_DeviceMaintainBill.[DBId] = T_DeviceBreakdown.Id
) nt
WHERE (MaintainAlarm= @MaintainAlarm or @MaintainAlarm is null)
and (nt.WeiXiu = @RanggeType or @RanggeType is null)
and (BreakdownLevel = @BreakdownLevel or @BreakdownLevel is null) --故障等级
and (cast(convert(varchar,DeclaredOn,112) as smalldatetime) = @DeclaredOn or @DeclaredOn is null)--申报时间
--cast(convert(varchar,DeclaredOn,112) as smalldatetime) 截取数据库带有时分秒时间段的年月日,用横杠表示
AND (nt.MaintainUserId=@MaintainUserId or @MaintainUserId is null)
and (WId =@WId or @WId is null)
return @PageTotal
dll文件下载: