使用ASP.NET 2.0 FormView显示数据


  本文标签:ASP.NET 2.0 FormView

  ASP.NET 2.0 FormView:添加一个FormView到CustomColors.aspx中,设置其ID为LowStockedProductsInRed,像前一个步骤一样绑定数据到ObjectDataSource中,这将在FormView中创建ItemTemplate, EditItemTemplate, 和InsertItemTemplate . 移除EditItemTemplate和InsertItemTemplate 并在 ItemTemplate 中仅包含ProductName 和UnitsInStock 项, 在智能感知中检查Allow Paging(分页)标记是否被选上

  在这些操作后FormView的代码大概会成这样

  1. < asp:FormView ID="LowStockedProductsInRed" runat="server" DataKeyNames="ProductID" 
  2.  
  3.     DataSourceID="ObjectDataSource1" AllowPaging="True" EnableViewState="False">              
  4.  
  5.     < ItemTemplate>  
  6.  
  7.         < b>Product:< /b>  
  8.  
  9.         < asp:Label ID="ProductNameLabel" runat="server" Text=< %# Bind("ProductName") %>>  
  10.  
  11.         < /asp:Label>< br />  
  12.  
  13.         < b>Units In Stock:< /b>  
  14.  
  15.         < asp:Label ID="UnitsInStockLabel" runat="server" Text=< %# Bind("UnitsInStock") %>>  
  16.  
  17.         < /asp:Label>  
  18.  
  19.     < /ItemTemplate>  
  20.  
  21. < /asp:FormView>  
  22.  

  ASP.NET 2.0 FormView的代码  。注意ItemTemplate 包含的代码:

  ◆静态HTML – “Product:” 和 “Units In Stock:” 包含 < br /> 和 < b> 元素.

  ◆Web 控件– 两个Label控件, ProductNameLabel 和UnitsInStockLabel.

  ◆绑定表达式 –< %# Bind("ProductName") %> 和< %# Bind("UnitsInStock") %> 表达式, 绑定值到Label的Text属性上

  以上就实现了在ASP.NET 2.0 FormView中显示数据  。