在ASP.NET GridView中显示产品信息

开发 后端
本文简单介绍了如何在GridView中显示产品信息。

要在ASP.NET GridView中显示产品信息,首先添加一个GridView到FormView的下方,设置ID为HighlightCheapProducts.我们之前已经设置了一个ObjectDataSource来获取产品数据,现在我们绑定GridView到ObjectDataSource. 之后,编辑GridView的绑定列包含产品的name.categorie,price属性。完成之后ASP.NET GridView的代码如下:

  1. < asp:GridView ID="HighlightCheapProducts" runat="server" AutoGenerateColumns="False" 
  2.  
  3.     DataKeyNames="ProductID" DataSourceID="ObjectDataSource1" EnableViewState="False">  
  4.  
  5.     < Columns>  
  6.  
  7.         < asp:BoundField DataField="ProductName" HeaderText="Product" SortExpression="ProductName" />  
  8.  
  9.         < asp:BoundField DataField="CategoryName" HeaderText="Category" ReadOnly="True" SortExpression="CategoryName" />  
  10.  
  11.         < asp:BoundField DataField="UnitPrice" DataFormatString="{0:c}" HeaderText="Price" 
  12.  
  13.             HtmlEncode="False" SortExpression="UnitPrice" />  
  14.  
  15.     < /Columns>  
  16.  
  17. < /asp:GridView>  
  18.  

下图显示浏览器查看的结果

GridView显示产品的name, category, price 

ASP.NET GridView: GridView显示产品的name, category, price

【编辑推荐】

  1. ASP.NET 2.0数据教程:SelectMethod属性的使用
  2. ASP.NET 2.0数据教程:在业务逻辑层添加方法
  3. ASP.NET 2.0数据教程:为TableAdapter添加方法
  4. ASP.NET 2.0数据教程:使用一个硬编码参数值
  5. ASP.NET 2.0数据教程:绑定到ObjectDataSource
责任编辑:book05 来源: 博客堂
相关推荐

2009-07-27 16:09:05

GridView显示数

2009-07-27 16:31:19

ASP.NET Det

2009-07-27 15:58:25

添加GridView

2009-07-27 10:12:37

GridView和Ob

2009-07-24 16:15:00

扩展ASP.NET G

2009-07-24 15:35:00

ASP.NET Gri

2009-07-20 18:02:48

GridView控件ASP.NET 2.0

2009-07-27 10:48:53

ASP.NET Det

2009-08-14 13:20:29

ASP.NET Gri

2009-07-27 16:22:54

GridView选择行

2012-04-06 13:52:58

ASP.NET

2009-07-29 15:51:29

ASP.NET中执行w

2012-04-09 10:34:21

jQuery

2012-11-08 10:27:22

WEB产品架构架构

2009-07-23 14:08:58

2009-01-16 13:17:16

AjaxASP.NET.NET

2009-07-23 16:44:51

AdRotator控件ASP.NET

2009-06-12 09:24:34

ASP.NET窗体ASP.NET MVC

2009-12-11 16:28:23

ASP.NET 2.0

2009-08-03 18:29:31

GridView与Da
点赞
收藏

51CTO技术栈公众号