DetailsView分頁(yè)顯示數(shù)據(jù)
在CustomFormatting文件夾下新建一個(gè)CustomColors.aspx頁(yè)面,從工具箱中拖出一個(gè)DetailsView控件到頁(yè)面中,設(shè)置ID為ExpensiveProductsPriceInBoldItalic
綁定到一個(gè)新的數(shù)據(jù)源中,并配置此數(shù)據(jù)源到業(yè)務(wù)對(duì)象ProductsBLL類(lèi)中的GetProducts()方法,這個(gè)的詳細(xì)實(shí)現(xiàn)步驟已經(jīng)在前面詳細(xì)介紹過(guò)了,這里就忽略了
當(dāng)您綁定ObjectDataSource到DetailsView時(shí),我們可以修改一下字段列表,我選擇移除了ProductID, SupplierID, CategoryID, UnitsInStock, UnitsOnOrder, ReorderLevel和那些不被綁定的字段,他們將不會(huì)顯示在DetailsView列表中,而那些留下來(lái)的我們可以重命名他們,還可以修改他們的顯示格式. 我還清空了DetailsView的Height和Width屬性,這樣當(dāng)顯示的只有一條數(shù)據(jù)時(shí)不會(huì)出現(xiàn)樣式的混亂。當(dāng)然我們面對(duì)的數(shù)據(jù)絕不只有一條這么少,顯示怎么辦呢?我們可以檢查DetailsView的智能感知中檢查Enable Paging checkbox是否被勾選上, 這樣我們可以分頁(yè)查看所有的數(shù)據(jù)了。
DetailsView分頁(yè): 在DetailsView的值能感知中檢查Enable Paging屬性是否被勾選上
在經(jīng)過(guò)這些改變后,DetailsView的代碼更改為
- < asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False" DataKeyNames="ProductID" DataSourceID="ObjectDataSource1" EnableViewState="False">
- < Fields>
- < asp:BoundField DataField="ProductName" HeaderText="Product" SortExpression="ProductName" />
- < asp:BoundField DataField="CategoryName" HeaderText="Category" ReadOnly="True" SortExpression="CategoryName" />
- < asp:BoundField DataField="SupplierName" HeaderText="Supplier" ReadOnly="True" SortExpression="SupplierName" />
- < asp:BoundField DataField="QuantityPerUnit" HeaderText="Qty/Unit" SortExpression="QuantityPerUnit" />
- < asp:BoundField DataField="UnitPrice" DataFormatString="{0:c}" HeaderText="Price"
- HtmlEncode="False" SortExpression="UnitPrice" />
- < /Fields>
- < /asp:DetailsView>
您這時(shí)可以按F5執(zhí)行看看DetailsView分頁(yè)效果
DetailsView分頁(yè): DetailsView控件一次顯示一個(gè)數(shù)據(jù)
【編輯推薦】