使用ASP.NET 2.0 FormView顯示數(shù)據(jù)
ASP.NET 2.0 FormView:添加一個FormView到CustomColors.aspx中,設(shè)置其ID為LowStockedProductsInRed,像前一個步驟一樣綁定數(shù)據(jù)到ObjectDataSource中,這將在FormView中創(chuàng)建ItemTemplate, EditItemTemplate, 和InsertItemTemplate . 移除EditItemTemplate和InsertItemTemplate 并在 ItemTemplate 中僅包含ProductName 和UnitsInStock 項, 在智能感知中檢查Allow Paging(分頁)標記是否被選上
在這些操作后FormView的代碼大概會成這樣
- < asp:FormView ID="LowStockedProductsInRed" runat="server" DataKeyNames="ProductID"
- DataSourceID="ObjectDataSource1" AllowPaging="True" EnableViewState="False">
- < ItemTemplate>
- < b>Product:< /b>
- < asp:Label ID="ProductNameLabel" runat="server" Text='< %# Bind("ProductName") %>'>
- < /asp:Label>< br />
- < b>Units In Stock:< /b>
- < asp:Label ID="UnitsInStockLabel" runat="server" Text='< %# Bind("UnitsInStock") %>'>
- < /asp:Label>
- < /ItemTemplate>
- < /asp:FormView>
ASP.NET 2.0 FormView的代碼。注意ItemTemplate 包含的代碼:
◆靜態(tài)HTML – “Product:” 和 “Units In Stock:” 包含 < br /> 和 < b> 元素.
◆Web 控件– 兩個Label控件, ProductNameLabel 和UnitsInStockLabel.
◆綁定表達式 –< %# Bind("ProductName") %> 和< %# Bind("UnitsInStock") %> 表達式, 綁定值到Label的Text屬性上
以上就實現(xiàn)了在ASP.NET 2.0 FormView中顯示數(shù)據(jù)。
【編輯推薦】