create proc up_GetPageData2
@LastRowIndex int , ---上一页的最后一行的下标
@pgSize float , --页容量
@rowCount int output, --- 输出总行数
@pgCount int output, --- 输出 总页数
@isDel bit --数据是否删除
as
begin
select @rowCount =count (*) from classes where cisdel= @isDel --查出总行数
set @pgCount =ceiling ( @rowCount/ @pgSize )-- 算出总页数
select * from (
select Row_Number () over ( order by cid ) as RNum, * from classes where cisdel= @isDel
) as temp
where RNum >@LastRowIndex and RNum <= @LastRowIndex +@pgSize
end
ListView.aspx代码如下:
复制代码 代码如下:
View Code
<% @ Page Language="C#" AutoEventWireup="true" CodeBehind="ListView.aspx.cs" Inherits ="WebForm.ListView" %>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns ="http://www.w3.org/1999/xhtml">
< head runat ="server">
<title ></ title>
</ head>
< body>
<form runat="server">
<div >
< asp: ObjectDataSource ID ="ObjectDataSource1" runat ="server"
SelectMethod ="getPageListByPage" TypeName ="BLL.Classes"
DataObjectTypeName ="MODEL.Classes" DeleteMethod ="SoftDel" InsertMethod ="Add"
UpdateMethod ="Modify" EnablePaging ="True"
MaximumRowsParameterName ="rowIndex" SelectCountMethod ="GetTotalRowsCount"
StartRowIndexParameterName ="pageSize">
</ asp: ObjectDataSource >
< asp: ListView ID ="ListView1" runat ="server" DataSourceID ="ObjectDataSource1"
InsertItemPosition ="LastItem">
< AlternatingItemTemplate>
< tr style ="">
< td>
< asp: Button ID ="DeleteButton" runat ="server" CommandName ="Delete" Text ="删除" />
< asp: Button ID ="EditButton" runat ="server" CommandName ="Edit" Text ="编辑" />
</ td>
< td>
< asp: Label ID ="CIDLabel" runat ="server" Text =' <%# Eval("CID") %> ' />
</ td>
< td>
< asp: Label ID ="CNameLabel" runat ="server" Text =' <%# Eval("CName") %> ' />
</ td>
< td>
< asp: Label ID ="CCountLabel" runat ="server" Text =' <%# Eval("CCount") %> ' />
</ td>
< td>
< asp: Label ID ="CImgLabel" runat ="server" Text =' <%# Eval("CImg") %> ' />
</ td>
< td>
< asp: CheckBox ID ="CIsDelCheckBox" runat ="server"
Checked ='<% # Eval("CIsDel") %> ' Enabled ="false" />
</ td>
< td>
< asp: Label ID ="CAddTimeLabel" runat ="server" Text =' <%# Eval("CAddTime") %> ' />
</ td>
</ tr>
</ AlternatingItemTemplate>
< EditItemTemplate>
< tr style ="">
< td>
< asp: Button ID ="UpdateButton" runat ="server" CommandName ="Update" Text ="更新" />
< asp: Button ID ="CancelButton" runat ="server" CommandName ="Cancel" Text ="取消" />
</ td>
< td>
< asp: TextBox ID ="CIDTextBox" runat ="server" Text =' <%# Bind("CID") %> ' />
</ td>
< td>
< asp: TextBox ID ="CNameTextBox" runat ="server" Text =' <%# Bind("CName") %> ' />
</ td>
< td>
< asp: TextBox ID ="CCountTextBox" runat ="server" Text =' <%# Bind("CCount") %> ' />
</ td>
< td>
< asp: TextBox ID ="CImgTextBox" runat ="server" Text =' <%# Bind("CImg") %> ' />
</ td>
< td>
< asp: CheckBox ID ="CIsDelCheckBox" runat ="server"
Checked ='<% # Bind("CIsDel") %> ' />
</ td>
< td>
< asp: TextBox ID ="CAddTimeTextBox" runat ="server"
Text ='<% # Bind("CAddTime") %> ' />
</ td>
</ tr>
</ EditItemTemplate>
< EmptyDataTemplate>
< table runat ="server"
style ="">
< tr>
< td>
未返回数据。 </ td>
</ tr>
</ table>
</ EmptyDataTemplate>
< InsertItemTemplate>
< tr style ="">
< td>
< asp: Button ID ="InsertButton" runat ="server" CommandName ="Insert" Text ="插入" />
< asp: Button ID ="CancelButton" runat ="server" CommandName ="Cancel" Text ="清除" />
</ td>
< td>
< asp: TextBox ID ="CIDTextBox" runat ="server" Text =' <%# Bind("CID") %> ' />
</ td>
< td>
< asp: TextBox ID ="CNameTextBox" runat ="server" Text =' <%# Bind("CName") %> ' />
</ td>
< td>
< asp: TextBox ID ="CCountTextBox" runat ="server" Text =' <%# Bind("CCount") %> ' />
</ td>
< td>
< asp: TextBox ID ="CImgTextBox" runat ="server" Text =' <%# Bind("CImg") %> ' />
</ td>
< td>
< asp: CheckBox ID ="CIsDelCheckBox" runat ="server"
Checked ='<% # Bind("CIsDel") %> ' />
</ td>
< td>
< asp: TextBox ID ="CAddTimeTextBox" runat ="server"
Text ='<% # Bind("CAddTime") %> ' />
</ td>
</ tr>
</ InsertItemTemplate>
< ItemTemplate>
< tr style ="">
< td>
< asp: Button ID ="DeleteButton" runat ="server" CommandName ="Delete" Text ="删除" />
< asp: Button ID ="EditButton" runat ="server" CommandName ="Edit" Text ="编辑" />
</ td>
< td>
< asp: Label ID ="CIDLabel" runat ="server" Text =' <%# Eval("CID") %> ' />
</ td>
< td>
< asp: Label ID ="CNameLabel" runat ="server" Text =' <%# Eval("CName") %> ' />
</ td>
< td>
< asp: Label ID ="CCountLabel" runat ="server" Text =' <%# Eval("CCount") %> ' />
</ td>
< td>
< asp: Label ID ="CImgLabel" runat ="server" Text =' <%# Eval("CImg") %> ' />
</ td>
< td>
< asp: CheckBox ID ="CIsDelCheckBox" runat ="server"
Checked ='<% # Eval("CIsDel") %> ' Enabled ="false" />
</ td>
< td>
< asp: Label ID ="CAddTimeLabel" runat ="server" Text =' <%# Eval("CAddTime") %> ' />
</ td>
</ tr>
</ ItemTemplate>
< LayoutTemplate>
< table runat ="server">
< tr runat ="server">
< td runat ="server">
< table ID ="itemPlaceholderContainer" runat ="server" border ="0"
style ="">
< tr runat ="server" style ="">
< th runat ="server">
</ th>
< th runat ="server">
CID </ th>
< th runat ="server">
CName </ th>
< th runat ="server">
CCount </ th>
< th runat ="server">
CImg </ th>
< th runat ="server">
CIsDel </ th>
< th runat ="server">
CAddTime </ th>
</ tr>
< tr ID ="itemPlaceholder" runat ="server">
</ tr>
</ table>
</ td>
</ tr>
< tr runat ="server">
< td runat ="server"
style ="">
</ td>
</ tr>
</ table>
</ LayoutTemplate>
< SelectedItemTemplate>
< tr style ="">
< td>
< asp: Button ID ="DeleteButton" runat ="server" CommandName ="Delete" Text ="删除" />
< asp: Button ID ="EditButton" runat ="server" CommandName ="Edit" Text ="编辑" />
</ td>
< td>
< asp: Label ID ="CIDLabel" runat ="server" Text =' <%# Eval("CID") %> ' />
</ td>
< td>
< asp: Label ID ="CNameLabel" runat ="server" Text =' <%# Eval("CName") %> ' />
</ td>
< td>
< asp: Label ID ="CCountLabel" runat ="server" Text =' <%# Eval("CCount") %> ' />
</ td>
< td>
< asp: Label ID ="CImgLabel" runat ="server" Text =' <%# Eval("CImg") %> ' />
</ td>
< td>
< asp: CheckBox ID ="CIsDelCheckBox" runat ="server"
Checked ='<% # Eval("CIsDel") %> ' Enabled ="false" />
</ td>
< td>
< asp: Label ID ="CAddTimeLabel" runat ="server" Text =' <%# Eval("CAddTime") %> ' />
</ td>
</ tr>
</ SelectedItemTemplate>
</ asp: ListView >
</div >
<asp : DataPager ID ="DataPager1" runat ="server" PagedControlID ="ListView1"
PageSize ="5">
< Fields>
< asp: NextPreviousPagerField ButtonType ="Button" ShowFirstPageButton ="True"
ShowLastPageButton ="True" />
</ Fields>
</asp : DataPager>
</form >
</ body>
</ html>
3、界面中ListView1取消"开启分页"自动分页 拖入分页控件DataPage并设置PagedControlID="ListView1"使其与ListView1建立关联
4、修改数据源调用的方法为getPageListByPage运行结果如下:
补充:
如果运行报错'ObjectDataSource“ObjectDataSource1”未能找到带参数的非泛型方法“getPageListByPage”: pageSize, pageIndex。'
只需删除aspx界面中
<SelectParameters>
<asp:Parameter DefaultValue="5" Type="Int32" />
<asp:Parameter Type="Int32" />
</SelectParameters>
您可能感兴趣的文章: