DetailsView分页显示数据

开发 后端
本文简单介绍了DetailsView分页显示数据的设置方法。简单的说,通过检查DetailsView的智能感知中检查Enable Paging checkbox是否被勾选上,就可以分页查看所有的数据了。

在CustomFormatting文件夹下新建一个CustomColors.aspx页面,从工具箱中拖出一个DetailsView控件到页面中,设置ID为ExpensiveProductsPriceInBoldItalic

绑定到一个新的数据源中,并配置此数据源到业务对象ProductsBLL类中的GetProducts()方法,这个的详细实现步骤已经在前面详细介绍过了,这里就忽略了

当您绑定ObjectDataSource到DetailsView时,我们可以修改一下字段列表,我选择移除了ProductID, SupplierID, CategoryID, UnitsInStock, UnitsOnOrder, ReorderLevel和那些不被绑定的字段,他们将不会显示在DetailsView列表中,而那些留下来的我们可以重命名他们,还可以修改他们的显示格式. 我还清空了DetailsView的Height和Width属性,这样当显示的只有一条数据时不会出现样式的混乱。当然我们面对的数据绝不只有一条这么少,显示怎么办呢?我们可以检查DetailsView的智能感知中检查Enable Paging checkbox是否被勾选上, 这样我们可以分页查看所有的数据了。

在DetailsView的值能感知中检查Enable Paging属性是否被勾选上 

DetailsView分页: 在DetailsView的值能感知中检查Enable Paging属性是否被勾选上

在经过这些改变后,DetailsView的代码更改为

  1. < asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" DataKeyNames="ProductID" DataSourceID="ObjectDataSource1" EnableViewState="False">  
  2.  
  3.     < Fields>  
  4.  
  5.         < asp:BoundField DataField="ProductName" HeaderText="Product" SortExpression="ProductName" />  
  6.  
  7.         < asp:BoundField DataField="CategoryName" HeaderText="Category" ReadOnly="True" SortExpression="CategoryName" />  
  8.  
  9.         < asp:BoundField DataField="SupplierName" HeaderText="Supplier" ReadOnly="True" SortExpression="SupplierName" />  
  10.  
  11.         < asp:BoundField DataField="QuantityPerUnit" HeaderText="Qty/Unit" SortExpression="QuantityPerUnit" />  
  12.  
  13.         < asp:BoundField DataField="UnitPrice" DataFormatString="{0:c}" HeaderText="Price" 
  14.  
  15.             HtmlEncode="False" SortExpression="UnitPrice" />  
  16.  
  17.     < /Fields>  
  18.  
  19. < /asp:DetailsView>  
  20.  

您这时可以按F5执行看看DetailsView分页效果

DetailsView控件一次显示一个数据 

DetailsView分页: DetailsView控件一次显示一个数据

【编辑推荐】

  1. ASP.NET 2.0数据教程:添加和配置ObjectDataSource控件
  2. ASP.NET 2.0数据教程:给每个部分添加Default.aspx页面
  3. ASP.NET 2.0数据教程:添加breadcrumb导航
  4. ASP.NET 2.0数据教程:SiteMapDataSource控件
  5. ASP.NET 2.0数据教程:添加站点地图
责任编辑:book05 来源: 博客堂
相关推荐

2009-07-27 10:48:53

ASP.NET Det

2009-07-27 16:31:19

ASP.NET Det

2010-11-29 09:45:30

Sybase分页

2009-12-28 15:38:36

ADO.NET分页

2020-05-20 16:54:47

数据分页显示函数

2010-05-17 17:35:30

MySQL数据库

2009-07-27 16:46:07

DetailsView

2022-01-10 10:12:58

MySQL分页数据

2009-08-04 14:23:36

ASP.NET查询分页

2010-09-17 10:26:01

iPhone

2009-07-03 14:23:49

JSP数据分页

2009-07-27 16:53:15

ASP.NET 2.0

2011-04-19 11:02:57

数据库分页

2010-03-19 09:17:16

ASP.NET MVC

2012-07-23 14:30:33

Oracle

2011-05-30 15:58:29

Android ListView 数据

2009-05-15 10:11:55

数据库查询查询性能分页浏览

2009-08-07 09:20:26

DataPager数据

2010-09-14 10:47:45

sql server存

2010-09-24 18:47:23

SQL数据分页
点赞
收藏

51CTO技术栈公众号