CheckBoxList.IRepeatInfoUser.RenderItem 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
如需這個成員的說明,請參閱 RenderItem(ListItemType, Int32, RepeatInfo, HtmlTextWriter)。
virtual void System.Web.UI.WebControls.IRepeatInfoUser.RenderItem(System::Web::UI::WebControls::ListItemType itemType, int repeatIndex, System::Web::UI::WebControls::RepeatInfo ^ repeatInfo, System::Web::UI::HtmlTextWriter ^ writer) = System::Web::UI::WebControls::IRepeatInfoUser::RenderItem;
void IRepeatInfoUser.RenderItem (System.Web.UI.WebControls.ListItemType itemType, int repeatIndex, System.Web.UI.WebControls.RepeatInfo repeatInfo, System.Web.UI.HtmlTextWriter writer);
abstract member System.Web.UI.WebControls.IRepeatInfoUser.RenderItem : System.Web.UI.WebControls.ListItemType * int * System.Web.UI.WebControls.RepeatInfo * System.Web.UI.HtmlTextWriter -> unit
override this.System.Web.UI.WebControls.IRepeatInfoUser.RenderItem : System.Web.UI.WebControls.ListItemType * int * System.Web.UI.WebControls.RepeatInfo * System.Web.UI.HtmlTextWriter -> unit
Sub RenderItem (itemType As ListItemType, repeatIndex As Integer, repeatInfo As RepeatInfo, writer As HtmlTextWriter) Implements IRepeatInfoUser.RenderItem
參數
- itemType
- ListItemType
其中一個 ListItemType 列舉值。
- repeatIndex
- Int32
序數索引,指定清單控制中項目的位置。
- repeatInfo
- RepeatInfo
RepeatInfo 物件,代表用來呈現清單中項目的資訊。
- writer
- HtmlTextWriter
HtmlTextWriter 物件,代表要在用戶端呈現 HTML 內容的輸出資料流。
實作
範例
下列程式碼範例示範如何在自訂 CheckBoxList 物件上使用 IRepeatInfoUser 介面成員。
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<!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>Custom CheckBoxList - IRepeatInfoUser - C# Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom CheckBoxList - IRepeatInfoUser - C# Example</h3>
<aspSample:CustomCheckBoxListIRepeatInfoUser
id="CheckBoxList1" runat="server">
<asp:ListItem Selected="True">Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</aspSample:CustomCheckBoxListIRepeatInfoUser>
</form>
</body>
</html>
<%@ Page language="VB" %>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<!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>Custom CheckBoxList - IRepeatInfoUser - VB.NET Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom CheckBoxList - IRepeatInfoUser - VB.NET Example</h3>
<aspSample:CustomCheckBoxListIRepeatInfoUser id="CheckBoxList" runat="server">
<asp:ListItem Selected="True">Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</aspSample:CustomCheckBoxListIRepeatInfoUser>
</form>
</body>
</html>
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Permissions;
namespace Samples.AspNet.CS.Controls
{
[AspNetHostingPermission(SecurityAction.Demand, Level =
AspNetHostingPermissionLevel.Minimal)]
public class CustomCheckBoxListIRepeatInfoUser : CheckBoxList
{
private bool hasFooter;
private bool hasHeader;
private bool hasSeparators;
private int repeatedItemCount;
private Style itemStyleItem;
protected override void OnPreRender(System.EventArgs e)
{
// Call the base class's OnPreRender method
base.OnPreRender(e);
// Get a self-referencing IRepeatInfoUser object
IRepeatInfoUser repeatInfoUser = (IRepeatInfoUser)this;
// Get the IRepeatInfoUser members values.
hasFooter = repeatInfoUser.HasFooter;
hasHeader = repeatInfoUser.HasHeader;
hasSeparators = repeatInfoUser.HasSeparators;
repeatedItemCount = repeatInfoUser.RepeatedItemCount;
itemStyleItem = repeatInfoUser.GetItemStyle(ListItemType.Item, 0);
}
protected override void Render(HtmlTextWriter writer)
{
// Create and setup a RepeatInfo class.
RepeatInfo repeatInfo = new RepeatInfo();
repeatInfo.RepeatColumns = 0;
repeatInfo.RepeatDirection = RepeatDirection.Horizontal;
repeatInfo.RepeatLayout = RepeatLayout.Table;
// Get a self-referencing IRepeatInfoUser object
IRepeatInfoUser repeatInfoUser = (IRepeatInfoUser)this;
// Render the items using the above RepeatInfo class.
repeatInfoUser.RenderItem(ListItemType.Item, 0, repeatInfo, writer);
repeatInfoUser.RenderItem(ListItemType.Item, 1, repeatInfo, writer);
repeatInfoUser.RenderItem(ListItemType.Item, 2, repeatInfo, writer);
repeatInfoUser.RenderItem(ListItemType.Item, 3, repeatInfo, writer);
repeatInfoUser.RenderItem(ListItemType.Item, 4, repeatInfo, writer);
repeatInfoUser.RenderItem(ListItemType.Item, 5, repeatInfo, writer);
}
}
}
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Security.Permissions
Namespace Samples.AspNet.VB.Controls
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class CustomCheckBoxListIRepeatInfoUser
Inherits CheckBoxList
Private _hasFooter As Boolean
Private _hasHeader As Boolean
Private _hasSeparators As Boolean
Private _repeatedItemCount As Integer
Private _itemStyleItem As Style
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
' Call the base class's OnPreRender method
MyBase.OnPreRender(e)
' Get a self-referencing IRepeatInfoUser object
Dim repeatInfoUser As IRepeatInfoUser
repeatInfoUser = CType(Me, IRepeatInfoUser)
' Get the IRepeatInfoUser member values.
_hasFooter = repeatInfoUser.HasFooter
_hasHeader = repeatInfoUser.HasHeader
_hasSeparators = repeatInfoUser.HasSeparators
_repeatedItemCount = repeatInfoUser.RepeatedItemCount
_itemStyleItem = repeatInfoUser.GetItemStyle(ListItemType.Item, 0)
End Sub
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
' Create and setup a RepeatInfo class.
Dim repeatInfo As New RepeatInfo
repeatInfo.RepeatColumns = 0
repeatInfo.RepeatDirection = RepeatDirection.Horizontal
repeatInfo.RepeatLayout = RepeatLayout.Table
' Get a self-referencing IRepeatInfoUser object
Dim repeatInfoUser As IRepeatInfoUser
repeatInfoUser = CType(Me, IRepeatInfoUser)
' Render the items using the above RepeatInfo and IRepeatInfoUser classes.
repeatInfoUser.RenderItem(ListItemType.Item, 0, repeatInfo, writer)
repeatInfoUser.RenderItem(ListItemType.Item, 1, repeatInfo, writer)
repeatInfoUser.RenderItem(ListItemType.Item, 2, repeatInfo, writer)
repeatInfoUser.RenderItem(ListItemType.Item, 3, repeatInfo, writer)
repeatInfoUser.RenderItem(ListItemType.Item, 4, repeatInfo, writer)
repeatInfoUser.RenderItem(ListItemType.Item, 5, repeatInfo, writer)
End Sub
End Class
End Namespace
備註
一般而言,您應該使用 CheckBoxList.RenderItem 方法來轉譯 物件中的 CheckBoxList 專案。
方法是 IRepeatInfoUser.RenderItem 明確的介面成員實作。 只有在 CheckBoxList 執行個體轉換成 IRepeatInfoUser 介面時,才能使用這個成員。
給繼承者的注意事項
若要定義自訂實作以轉譯 物件中的 CheckBoxList 專案,請覆寫 RenderItem(ListItemType, Int32, RepeatInfo, HtmlTextWriter) 成員。 明確介面實作會 RenderItem(ListItemType, Int32, RepeatInfo, HtmlTextWriter) 呼叫 方法,以呈現 控制項中的專案。