DataGridItem 类
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示 DataGrid 控件中的项(行)。
public ref class DataGridItem : System::Web::UI::WebControls::TableRow, System::Web::UI::INamingContainer
public ref class DataGridItem : System::Web::UI::WebControls::TableRow, System::Web::UI::IDataItemContainer
public class DataGridItem : System.Web.UI.WebControls.TableRow, System.Web.UI.INamingContainer
public class DataGridItem : System.Web.UI.WebControls.TableRow, System.Web.UI.IDataItemContainer
type DataGridItem = class
inherit TableRow
interface INamingContainer
type DataGridItem = class
inherit TableRow
interface IDataItemContainer
interface INamingContainer
Public Class DataGridItem
Inherits TableRow
Implements INamingContainer
Public Class DataGridItem
Inherits TableRow
Implements IDataItemContainer
- 继承
- 实现
下面的代码示例演示如何使用 DataGridItem 对象来显示控件中 DataGrid 每个数据项的内容。
备注
下面的代码示例使用单文件代码模型,如果直接复制到代码隐藏文件中,可能无法正常工作。 必须将此代码示例复制到扩展名为 .aspx 的空文本文件中。 有关Web Forms代码模型的详细信息,请参阅处理和引发事件。
<%@ Page Language="C#" AutoEventWireup="True" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<script runat="server">
ICollection CreateDataSource()
{
// Create sample data for the DataGrid control.
DataTable dt = new DataTable();
DataRow dr;
// Define the columns of the table.
dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue", typeof(String)));
dt.Columns.Add(new DataColumn("CurrencyValue", typeof(Double)));
// Populate the table with sample values.
for (int i=0; i<=10; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "Item " + i.ToString();
dr[2] = 1.23 * (i + 1);
dt.Rows.Add(dr);
}
DataView dv = new DataView(dt);
return dv;
}
void Page_Load(Object sender, EventArgs e)
{
// Load sample data only once, when the page is first loaded.
if (!IsPostBack)
{
ItemsGrid.DataSource = CreateDataSource();
ItemsGrid.DataBind();
}
}
void Item_Bound(Object sender, DataGridItemEventArgs e)
{
// Use the ItemDataBound event to customize the DataGrid control.
// The ItemDataBound event allows you to access the data before
// the item is displayed in the control. In this example, the
// ItemDataBound event is used to format the items in the
// CurrencyColumn in currency format.
if((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
{
// Retrieve the text of the CurrencyColumn from the DataGridItem
// and convert the value to a Double.
Double Price = Convert.ToDouble(e.Item.Cells[2].Text);
// Format the value as currency and redisplay it in the DataGrid.
e.Item.Cells[2].Text = Price.ToString("c");
}
}
</script>
<head runat="server">
<title>DataGrid ItemDataBound Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>DataGrid ItemDataBound Example</h3>
<asp:DataGrid id="ItemsGrid" runat="server"
BorderColor="black"
BorderWidth="1"
CellPadding="3"
ShowFooter="true"
OnItemDataBound="Item_Bound">
<HeaderStyle BackColor="#00aaaa">
</HeaderStyle>
<FooterStyle BackColor="#00aaaa">
</FooterStyle>
</asp:DataGrid>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<script runat="server">
Function CreateDataSource() As ICollection
' Create sample data for the DataGrid control.
Dim dt As DataTable = New DataTable()
Dim dr As DataRow
' Define the columns of the table.
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
' Populate the table with sample values.
Dim i As Integer
For i=0 To 10
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " & i.ToString()
dr(2) = 1.23 * (i + 1)
dt.Rows.Add(dr)
Next i
Dim dv As DataView = New DataView(dt)
return dv
End Function
Sub Page_Load(sender As Object, e As EventArgs)
' Load sample data only once, when the page is first loaded.
If Not IsPostBack Then
ItemsGrid.DataSource = CreateDataSource()
ItemsGrid.DataBind()
End If
End Sub
Sub Item_Bound(sender As Object, e As DataGridItemEventArgs)
' Use the ItemDataBound event to customize the DataGrid control.
' The ItemDataBound event allows you to access the data before
' the item is displayed in the control. In this example, the
' ItemDataBound event is used to format the items in the
' CurrencyColumn in currency format.
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
' Retrieve the text of the CurrencyColumn from the DataGridItem
' and convert the value to a Double.
Dim Price As Double = Convert.ToDouble(e.Item.Cells(2).Text)
' Format the value as currency and redisplay it in the DataGrid.
e.Item.Cells(2).Text = Price.ToString("c")
End If
End Sub
</script>
<head runat="server">
<title>DataGrid ItemDataBound Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>DataGrid ItemDataBound Example</h3>
<asp:DataGrid id="ItemsGrid" runat="server"
BorderColor="black"
BorderWidth="1"
CellPadding="3"
ShowFooter="true"
OnItemDataBound="Item_Bound">
<HeaderStyle BackColor="#00aaaa">
</HeaderStyle>
<FooterStyle BackColor="#00aaaa">
</FooterStyle>
</asp:DataGrid>
</form>
</body>
</html>
DataGridItem对象表示控件中的DataGrid项 (行) ,例如标题节、页脚节或数据行。
控件的数据项DataGrid存储在可以使用 控件的 属性访问Items的DataGrid集合中DataGridItemCollection。
可以使用 DataGridItem 对象以编程方式访问控件中 DataGrid 项的属性。
Access |
获取或设置使您得以快速导航到 Web 服务器控件的访问键。 (继承自 WebControl) |
Adapter |
获取控件的浏览器特定适配器。 (继承自 Control) |
App |
获取或设置包含该控件的 Page 或 UserControl 对象的应用程序相对虚拟目录。 (继承自 Control) |
Attributes |
获取与控件的特性不对应的任意特性(只用于呈现)的集合。 (继承自 WebControl) |
Back |
获取或设置 Web 服务器控件的背景色。 (继承自 WebControl) |
Binding |
获取包含该控件的数据绑定的控件。 (继承自 Control) |
Border |
获取或设置 Web 控件的边框颜色。 (继承自 WebControl) |
Border |
获取或设置 Web 服务器控件的边框样式。 (继承自 WebControl) |
Border |
获取或设置 Web 服务器控件的边框宽度。 (继承自 WebControl) |
Cells |
获取 TableCell 对象的集合,这些对象表示 Table 控件中的行的单元格。 (继承自 TableRow) |
Child |
获取一个值,该值指示是否已创建服务器控件的子控件。 (继承自 Control) |
ClientID |
获取由 ASP.NET 生成的 HTML 标记的控件 ID。 (继承自 Control) |
Client |
获取或设置用于生成 ClientID 属性值的算法。 (继承自 Control) |
Client |
获取一个字符值,该值表示 ClientID 属性中使用的分隔符字符。 (继承自 Control) |
Context |
为当前 Web 请求获取与服务器控件关联的 HttpContext 对象。 (继承自 Control) |
Controls |
获取 ControlCollection 对象,该对象表示 UI 层次结构中的指定服务器控件的子控件。 (继承自 Control) |
Control |
获取 Web 服务器控件的样式。 此属性主要由控件开发人员使用。 (继承自 WebControl) |
Control |
获取一个值,该值指示是否已为 Style 属性创建了 ControlStyle 对象。 此属性主要由控件开发人员使用。 (继承自 WebControl) |
Css |
获取或设置由 Web 服务器控件在客户端呈现的级联样式表 (CSS) 类。 (继承自 WebControl) |
Data |
获取或设置由 DataGridItem 控件中的 DataGrid 对象表示的数据项。 |
Data |
如果命名容器实现 IDataItemContainer,则获取对命名容器的引用。 (继承自 Control) |
Data |
如果命名容器实现 IDataKeysControl,则获取对命名容器的引用。 (继承自 Control) |
Data |
获取绑定数据源中的 DataGridItem 对象的索引。 |
Design |
获取一个值,该值指示是否正在使用设计图面上的一个控件。 (继承自 Control) |
Enabled |
获取或设置一个值,该值指示是否启用 Web 服务器控件。 (继承自 WebControl) |
Enable |
获取或设置一个值,该值指示主题是否应用于该控件。 (继承自 WebControl) |
Enable |
获取或设置一个值,该值指示服务器控件是否向发出请求的客户端保持自己的视图状态以及它所包含的任何子控件的视图状态。 (继承自 Control) |
Events |
获取控件的事件处理程序委托列表。 此属性为只读。 (继承自 Control) |
Font |
获取与 Web 服务器控件关联的字体属性。 (继承自 WebControl) |
Fore |
获取或设置 Web 服务器控件的前景色(通常是文本颜色)。 (继承自 WebControl) |
Has |
获取一个值,该值指示控件是否具有特性集。 (继承自 WebControl) |
Has |
获取一个值,该值指示当前服务器控件的子控件是否具有任何已保存的视图状态设置。 (继承自 Control) |
Height |
获取或设置 Web 服务器控件的高度。 (继承自 WebControl) |
Horizontal |
获取或设置行内容的水平对齐方式。 (继承自 TableRow) |
ID |
获取或设置分配给服务器控件的编程标识符。 (继承自 Control) |
Id |
获取用于分隔控件标识符的字符。 (继承自 Control) |
Is |
获取一个值,该值指示该控件中包含的控件是否具有控件状态。 (继承自 Control) |
Is |
获取一个值,该值指示是否启用控件。 (继承自 WebControl) |
Is |
获取一个值,用于指示服务器控件是否会将更改保存到其视图状态中。 (继承自 Control) |
Is |
获取一个值,该值指示是否为该控件启用了视图状态。 (继承自 Control) |
Item |
获取来自 DataGridItem 控件的 Items 集合的 DataGrid 对象的索引。 |
Item |
获取由 DataGridItem 控件中 DataGrid 对象表示的项的类型。 |
Load |
获取一个值,该值指示控件是否通过 ID 而不是索引参与加载其视图状态。 (继承自 Control) |
Naming |
获取对服务器控件的命名容器的引用,此引用创建唯一的命名空间,以区分具有相同 ID 属性值的服务器控件。 (继承自 Control) |
Page |
获取对包含服务器控件的 Page 实例的引用。 (继承自 Control) |
Parent |
获取对页 UI 层次结构中服务器控件的父控件的引用。 (继承自 Control) |
Rendering |
获取一个值,该值指定呈现的 HTML 将与之兼容的 ASP.NET 版本。 (继承自 Control) |
Site |
获取容器信息,该容器在呈现于设计图面上时承载当前控件。 (继承自 Control) |
SkinID |
获取或设置要应用于控件的外观。 (继承自 WebControl) |
Style |
获取将在 Web 服务器控件的外部标记上呈现为样式特性的文本特性的集合。 (继承自 WebControl) |
Supports |
获取一个值,该值指示在控件的 |
Tab |
获取或设置 Web 服务器控件的选项卡索引。 (继承自 WebControl) |
Table |
获取或设置 TableRow 控件中 Table 对象的位置。 (继承自 TableRow) |
Tag |
获取对应于此 Web 服务器控件的 HtmlTextWriterTag 值。 此属性主要由控件开发人员使用。 (继承自 WebControl) |
Tag |
获取控件标记的名称。 此属性主要由控件开发人员使用。 (继承自 WebControl) |
Template |
获取或设置对包含该控件的模板的引用。 (继承自 Control) |
Template |
获取包含当前服务器控件的 Page 或 UserControl 的虚拟目录。 (继承自 Control) |
Tool |
获取或设置当鼠标指针悬停在 Web 服务器控件上时显示的文本。 (继承自 WebControl) |
UniqueID |
获取服务器控件的唯一的、以分层形式限定的标识符。 (继承自 Control) |
Validate |
获取或设置指示控件是否检查来自浏览器的客户端输入是否具有潜在危险值的值。 (继承自 Control) |
Vertical |
获取或设置行内容的垂直对齐方式。 (继承自 TableRow) |
View |
获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原服务器控件的视图状态。 (继承自 Control) |
View |
获取一个值,该值指示 StateBag 对象是否不区分大小写。 (继承自 Control) |
View |
获取或设置此控件的视图状态模式。 (继承自 Control) |
Visible |
获取或设置一个值,该值指示服务器控件是否作为 UI 呈现在页上。 (继承自 Control) |
Width |
获取或设置 Web 服务器控件的宽度。 (继承自 WebControl) |
Data |
当服务器控件绑定到数据源时发生。 (继承自 Control) |
Disposed |
当从内存释放服务器控件时发生,这是请求 ASP.NET 页时服务器控件生存期的最后阶段。 (继承自 Control) |
Init |
当服务器控件初始化时发生;初始化是控件生存期的第一步。 (继承自 Control) |
Load |
当服务器控件加载到 Page 对象中时发生。 (继承自 Control) |
Pre |
在加载 Control 对象之后、呈现之前发生。 (继承自 Control) |
Unload |
当服务器控件从内存中卸载时发生。 (继承自 Control) |
Find |
返回与指定控件的数据控件关联的数据源。 |
Find |
返回指定控件的命名容器中指定列的字段模板。 |
Find |
返回包含数据控件的元表对象。 |
Get |
为指定数据控件获取默认值的集合。 |
Get |
为指定数据控件获取表元数据。 |
Set |
为指定数据控件设置表元数据。 |
Set |
为指定数据控件设置表元数据和默认值映射。 |
Set |
为指定数据控件设置表元数据和默认值映射。 |
Try |
确定表元数据是否可用。 |
Enable |
为指定数据控件启用动态数据行为。 |
Enable |
为指定数据控件启用动态数据行为。 |
Enable |
为指定数据控件启用动态数据行为。 |
产品 | 版本 |
---|---|
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |