- 时间:2021-03-31 18:31 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:ASP.NET笔记之 行命令处理与分页详解
[b]1、行命令处理[/b]
[b](1、 后台代码:操作行[/b]
//如果是来自html响应中的该函数操作
if(e.CommandName=="addAge"){
//取得行号
int index=((ListViewDataItem)e.Item)DispalyIndex;
//取得当前操作行的主键值
//DataKeys存的是所有ID,取的是第index个ID
Guid id=(Guid)ListView1.DataKeys[index].Value;
表Adapter adapter=new 表Adapter();
adpter.自定义数据库函数addAge;
//数据绑定
ListView.DataBing();
}
[b](2、排序
[/b]CommandName="Sort"
CommandArgument="ID"
内部排序,效率较低
[b]2、DataPager 分页[/b]
[img]http://img.1sucai.cn/uploads/article/2018010709/20180107090126_0_87120.jpg[/img]
PageControlID:给哪个ListView分页
[img]http://img.1sucai.cn/uploads/article/2018010709/20180107090127_1_6770.jpg[/img]
[b]高级分页:[/b]
[img]http://img.1sucai.cn/uploads/article/2018010709/20180107090127_2_57086.jpg[/img]
[b]查询子查询
[/b]select* from
(Select id,name,age,row_number() over(order by id)rownum from T_Users)t
where t.rownum>11and t.rownum<20
[img]http://img.1sucai.cn/uploads/article/2018010709/20180107090128_3_96201.jpg[/img]
[b]3、高效分页:[/b]
[img]http://img.1sucai.cn/uploads/article/2018010709/20180107090128_4_37824.jpg[/img]
[b](1、数据库方法:[/b]
//获取本页的行数
开始的行数:startRowIndex
开始加本页的行数:startRowIndex+maximumRows
//数据库方法:GetCount
select Count(*)from T_Users
//数据库方法名:QueryCount
select* from
(
select Id ,Name,Gender,Row_Number() over(order by Id)rownum FROM dbo.T_User
)t
where t.rownum>@startRowIndex and t.rowRow<=@startRowIndex+@maximumRows
由于startRowIndex+maximumRows两个参数不会帮我们生成,需要我们自己手动添加。
[b](2、页面[/b]
**不要<SelectParameters>
**增加一个SelectCountMethod="QueryCount"设置取得行数的方法
而SelectMethod="GetPageData"是取得分页信息
而EnablePaging="true"
**先按正常流程配置ListView的objectDataSource,让ListVIew自动生成
再去配置分页数据源