RepeaterItem 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示控件中的 Repeater 项。
public ref class RepeaterItem : System::Web::UI::Control, System::Web::UI::INamingContainer
public ref class RepeaterItem : System::Web::UI::Control, System::Web::UI::IDataItemContainer
public class RepeaterItem : System.Web.UI.Control, System.Web.UI.INamingContainer
public class RepeaterItem : System.Web.UI.Control, System.Web.UI.IDataItemContainer
type RepeaterItem = class
inherit Control
interface INamingContainer
type RepeaterItem = class
inherit Control
interface IDataItemContainer
interface INamingContainer
Public Class RepeaterItem
Inherits Control
Implements INamingContainer
Public Class RepeaterItem
Inherits Control
Implements IDataItemContainer
- 继承
- 实现
示例
以下示例演示如何使用 RepeaterItem 对象来显示控件中 Repeater 每个数据项的内容。
<%@ Page Language="C#" 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" >
<head>
<title>Repeater Example</title>
<script language="C#" runat="server">
void Page_Load(Object Sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList values = new ArrayList();
values.Add(new PositionData("Item 1", "$6.00"));
values.Add(new PositionData("Item 2", "$7.48"));
values.Add(new PositionData("Item 3", "$9.96"));
Repeater1.DataSource = values;
Repeater1.DataBind();
}
}
void Button_Click(Object Sender, EventArgs e)
{
Label1.Text = "The Items collection contains: <br />";
foreach(RepeaterItem item in Repeater1.Items)
{
Label1.Text += ((DataBoundLiteralControl)item.Controls[0]).Text +
"<br />";
}
}
public class PositionData
{
private string item;
private string price;
public PositionData(string item, string price)
{
this.item = item;
this.price = price;
}
public string Item
{
get
{
return item;
}
}
public string Price
{
get
{
return price;
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Repeater Example</h3>
<br />
<asp:Repeater id="Repeater1"
runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<td><b>Item</b></td>
<td><b>Price</b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td> <%# DataBinder.Eval(Container.DataItem, "Item") %> </td>
<td> <%# DataBinder.Eval(Container.DataItem, "Price") %> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<br />
<asp:Button id="Button1"
Text="Display Items in Repeater"
OnClick="Button_Click"
runat="server"/>
<br /><br />
<asp:Label id="Label1"
runat="server"/>
</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" >
<head>
<title>Repeater Example</title>
<script language="VB" runat="server">
Sub Page_Load(Sender As Object, e As EventArgs)
If Not IsPostBack Then
Dim values As New ArrayList()
values.Add(New PositionData("Item 1", "$6.00"))
values.Add(New PositionData("Item 2", "$7.48"))
values.Add(New PositionData("Item 3", "$9.96"))
Repeater1.DataSource = values
Repeater1.DataBind()
End If
End Sub
Sub Button_Click(Sender As Object, e As EventArgs)
Label1.Text = "The Items collection contains: <br />"
Dim item As RepeaterItem
For Each item In Repeater1.Items
Label1.Text &= _
CType(item.Controls(0), DataBoundLiteralControl).Text & "<br />"
Next item
End Sub
Public Class PositionData
Private myItem As String
Private myPrice As String
Public Sub New(newItem As String, newPrice As String)
Me.myItem = newItem
Me.myPrice = newPrice
End Sub
Public ReadOnly Property Item() As String
Get
Return myItem
End Get
End Property
Public ReadOnly Property Price() As String
Get
Return myPrice
End Get
End Property
End Class
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Repeater Example</h3>
<br />
<asp:Repeater id="Repeater1"
runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<td><b>Item</b></td>
<td><b>Price</b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td> <%# DataBinder.Eval(Container.DataItem, "Item") %> </td>
<td> <%# DataBinder.Eval(Container.DataItem, "Price") %> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<br />
<asp:Button id="Button1"
Text="Display Items in Repeater"
OnClick="Button_Click"
runat="server"/>
<br /><br />
<asp:Label id="Label1"
runat="server"/>
</form>
</body>
</html>
注解
对象 RepeaterItem 表示控件中的 Repeater 项,例如标题节、页脚节或数据项。
控件的数据项 Repeater 存储在 RepeaterItemCollection 可以使用控件的属性访问 Items 的对象中 Repeater 。
可以使用 RepeaterItem 对象以编程方式访问控件中 Repeater 项的属性。
构造函数
| 名称 | 说明 |
|---|---|
| RepeaterItem(Int32, ListItemType) |
初始化 RepeaterItem 类的新实例。 |
属性
| 名称 | 说明 |
|---|---|
| Adapter |
获取控件的特定于浏览器的适配器。 (继承自 Control) |
| AppRelativeTemplateSourceDirectory |
获取或设置包含此控件的 Page 或 UserControl 对象的应用程序相对虚拟目录。 (继承自 Control) |
| BindingContainer |
获取包含此控件的数据绑定的控件。 (继承自 Control) |
| ChildControlsCreated |
获取一个值,该值指示是否已创建服务器控件的子控件。 (继承自 Control) |
| ClientID |
获取由 ASP.NET 生成的 HTML 标记的控件 ID。 (继承自 Control) |
| ClientIDMode |
获取或设置用于生成属性值的 ClientID 算法。 (继承自 Control) |
| ClientIDSeparator |
获取一个表示属性中使用的 ClientID 分隔符的字符值。 (继承自 Control) |
| Context |
HttpContext获取与当前 Web 请求的服务器控件关联的对象。 (继承自 Control) |
| Controls |
获取一个 ControlCollection 对象,该对象代表 UI 层次结构中指定服务器控件的子控件。 (继承自 Control) |
| DataItem |
获取或设置与控件中的RepeaterItem对象关联的Repeater数据项。 |
| DataItemContainer |
获取对命名容器的引用(如果命名容器实现 IDataItemContainer)。 (继承自 Control) |
| DataKeysContainer |
获取对命名容器的引用(如果命名容器实现 IDataKeysControl)。 (继承自 Control) |
| DesignMode |
获取一个值,该值指示控件是否在设计图面上使用。 (继承自 Control) |
| EnableTheming |
获取或设置一个值,该值指示主题是否应用于此控件。 (继承自 Control) |
| EnableViewState |
获取或设置一个值,该值指示服务器控件是否将视图状态及其包含的任何子控件的视图状态保存到请求客户端。 (继承自 Control) |
| Events |
获取控件的事件处理程序委托的列表。 此属性为只读。 (继承自 Control) |
| HasChildViewState |
获取一个值,该值指示当前服务器控件的子控件是否具有保存的视图状态设置。 (继承自 Control) |
| ID |
获取或设置分配给服务器控件的编程标识符。 (继承自 Control) |
| IdSeparator |
获取用于分隔控件标识符的字符。 (继承自 Control) |
| IsChildControlStateCleared |
获取一个值,该值指示此控件中包含的控件是否具有控件状态。 (继承自 Control) |
| IsTrackingViewState |
获取一个值,该值指示服务器控件是否正在保存对其视图状态的更改。 (继承自 Control) |
| IsViewStateEnabled |
获取一个值,该值指示是否为此控件启用视图状态。 (继承自 Control) |
| ItemIndex | |
| ItemType |
获取控件中 Repeater 项的类型。 |
| LoadViewStateByID |
获取一个值,该值指示控件是否参与加载其视图状态,而不是 ID 索引。 (继承自 Control) |
| NamingContainer |
获取对服务器控件命名容器的引用,该容器创建唯一的命名空间,用于区分具有相同 ID 属性值的服务器控件。 (继承自 Control) |
| Page |
获取对 Page 包含服务器控件的实例的引用。 (继承自 Control) |
| Parent |
获取对页面控件层次结构中服务器控件的父控件的引用。 (继承自 Control) |
| RenderingCompatibility |
获取一个值,该值指定呈现的 HTML 将与 ASP.NET 版本兼容。 (继承自 Control) |
| Site |
获取有关在设计图面上呈现时承载当前控件的容器的信息。 (继承自 Control) |
| SkinID |
获取或设置要应用于控件的皮肤。 (继承自 Control) |
| TemplateControl |
获取或设置对包含此控件的模板的引用。 (继承自 Control) |
| TemplateSourceDirectory |
获取包含当前服务器控件的 Page 虚拟 UserControl 目录。 (继承自 Control) |
| UniqueID |
获取服务器控件的唯一分层限定标识符。 (继承自 Control) |
| ValidateRequestMode |
获取或设置一个值,该值指示控件是否检查浏览器的客户端输入是否存在潜在危险值。 (继承自 Control) |
| ViewState |
获取状态信息的字典,该字典允许跨同一页的多个请求保存和还原服务器控件的视图状态。 (继承自 Control) |
| ViewStateIgnoresCase |
获取一个值,该值指示对象是否 StateBag 不区分大小写。 (继承自 Control) |
| ViewStateMode |
获取或设置此控件的视图状态模式。 (继承自 Control) |
| Visible |
获取或设置一个值,该值指示服务器控件是否呈现为页面上的 UI。 (继承自 Control) |
方法
活动
| 名称 | 说明 |
|---|---|
| DataBinding |
当服务器控件绑定到数据源时发生。 (继承自 Control) |
| Disposed |
在从内存中释放服务器控件时发生,这是请求 ASP.NET 页时服务器控件生命周期的最后阶段。 (继承自 Control) |
| Init |
在初始化服务器控件时发生,这是其生命周期中的第一步。 (继承自 Control) |
| Load |
在将服务器控件加载到对象中 Page 时发生。 (继承自 Control) |
| PreRender |
在 Control 加载对象但在呈现之前发生。 (继承自 Control) |
| Unload |
从内存中卸载服务器控件时发生。 (继承自 Control) |
显式接口实现
扩展方法
| 名称 | 说明 |
|---|---|
| EnableDynamicData(INamingContainer, Type, IDictionary<String,Object>) |
为指定的数据控件启用动态数据行为。 |
| EnableDynamicData(INamingContainer, Type, Object) |
为指定的数据控件启用动态数据行为。 |
| EnableDynamicData(INamingContainer, Type) |
为指定的数据控件启用动态数据行为。 |
| FindDataSourceControl(Control) |
返回与指定控件的数据控件关联的数据源。 |
| FindFieldTemplate(Control, String) |
返回指定控件命名容器中指定列的字段模板。 |
| FindMetaTable(Control) |
返回包含数据控件的元表对象。 |
| GetDefaultValues(INamingContainer) |
获取指定数据控件的默认值的集合。 |
| GetMetaTable(INamingContainer) |
获取指定数据控件的表元数据。 |
| SetMetaTable(INamingContainer, MetaTable, IDictionary<String,Object>) |
设置指定数据控件的表元数据和默认值映射。 |
| SetMetaTable(INamingContainer, MetaTable, Object) |
设置指定数据控件的表元数据和默认值映射。 |
| SetMetaTable(INamingContainer, MetaTable) |
设置指定数据控件的表元数据。 |
| TryGetMetaTable(INamingContainer, MetaTable) |
确定表元数据是否可用。 |