使用ASP.NET 2.0 FormView显示数据

开发 后端
本文介绍了如何在FormView中显示产品信息。ASP.NET 2.0 FormView与ObjectDataSource的绑定,和DetailsView等控件是类似的。

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中显示数据。

【编辑推荐】

  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-21 15:27:12

ASP.NET 2.0

2009-07-27 16:09:05

GridView显示数

2009-01-07 11:38:22

ASP.NET.NET错误记录

2009-07-22 17:21:27

ASP.NET 2.0

2009-07-28 14:06:28

ASP.NET 2.0

2009-07-27 09:39:04

SelectMetho

2009-12-03 13:34:36

Visual Stud

2009-07-23 14:08:58

2009-07-24 17:15:52

SiteMapData

2009-07-22 17:23:03

XmlDataSourASP.NET 2.0

2009-07-30 15:17:16

ASP.NET 2.0

2009-07-21 15:55:59

使用Web PartsASP.NET 2.0

2009-08-05 17:43:48

ASP.NET 2.0

2009-08-05 17:26:25

ASP.NET 2.0

2009-07-24 12:41:21

BLL类

2009-07-24 16:37:04

创建母版页asp.net 2.0

2009-07-27 03:21:00

breadcrumb导

2009-07-27 09:01:44

ObjectDataS

2009-07-27 16:22:54

GridView选择行

2009-07-24 13:25:43

创建数据访问层
点赞
收藏

51CTO技术栈公众号