CheckBoxList.IRepeatInfoUser.GetItemStyle(ListItemType, Int32) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
有关此成员的说明,请参见 GetItemStyle(ListItemType, Int32)。
virtual System::Web::UI::WebControls::Style ^ System.Web.UI.WebControls.IRepeatInfoUser.GetItemStyle(System::Web::UI::WebControls::ListItemType itemType, int repeatIndex) = System::Web::UI::WebControls::IRepeatInfoUser::GetItemStyle;
System.Web.UI.WebControls.Style IRepeatInfoUser.GetItemStyle (System.Web.UI.WebControls.ListItemType itemType, int repeatIndex);
abstract member System.Web.UI.WebControls.IRepeatInfoUser.GetItemStyle : System.Web.UI.WebControls.ListItemType * int -> System.Web.UI.WebControls.Style
override this.System.Web.UI.WebControls.IRepeatInfoUser.GetItemStyle : System.Web.UI.WebControls.ListItemType * int -> System.Web.UI.WebControls.Style
Function GetItemStyle (itemType As ListItemType, repeatIndex As Integer) As Style Implements IRepeatInfoUser.GetItemStyle
参数
- itemType
- ListItemType
ListItemType 枚举值之一。
- repeatIndex
- Int32
指定列表控件中项的位置的序号索引。
返回
Style 对象,表示列表控件中指定索引位置的指定项类型的样式。
实现
示例
下面的代码示例演示如何在自定义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.GetItemStyle 该方法检索对象中 CheckBoxList 项的样式。
该方法 IRepeatInfoUser.GetItemStyle 是显式接口成员实现。 它只能在 CheckBoxList 实例被强制转换为 IRepeatInfoUser 接口时使用。
继承者说明
若要定义用于检索对象中 CheckBoxList 项样式的自定义实现,请重写 GetItemStyle(ListItemType, Int32) 成员。 显式接口实现调用 GetItemStyle(ListItemType, Int32) 该方法以检索项的样式。