PagedControl.ItemWeight プロパティ

定義

コントロール内の 1 つの項目のおおよそのウェイトを取得します。 この API は、互換性のために残されています。 ASP.NET モバイル アプリケーションを開発する方法については、「ASP.NET を使用した Mobile Apps & サイト」を参照してください。

protected:
 virtual property int ItemWeight { int get(); };
protected virtual int ItemWeight { get; }
member this.ItemWeight : int
Protected Overridable ReadOnly Property ItemWeight As Integer

プロパティ値

コントロール内の 1 つの項目のおおよそのウェイト。

次のコード例では、カスタム リスト コントロールを作成して使用します。 この例では、 クラスの プロパティを ItemWeight オーバーライドして、新しいコントロールの List 重みを指定する方法を示します。

<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Security.Permissions" %>

<script runat="server">
    // A custom list control for illustration
    [AspNetHostingPermission(SecurityAction.Demand, 
        Level=AspNetHostingPermissionLevel.Minimal), 
    AspNetHostingPermission(SecurityAction.InheritanceDemand, 
        Level=AspNetHostingPermissionLevel.Minimal)]
    public class ListControl : List
    {
        public ListControl()
            : base()
        {}

        // Set a weight for the items
        protected override int ItemWeight
        {
            get { return 150; }
        }
    }

    ListControl List1;
    
    private void Page_Load(object sender, 
        System.EventArgs e)
    {
        // Instantiate the custom control
        List1 = new ListControl();
        List1.ItemCount = 20;
        List1.ID = "List1";
        List1.LoadItems += this.LoadNow;
        Form1.Controls.Add(List1);

        Form1.ControlToPaginate = List1;
    }

    // Called by the List whenever it needs new items
    private void LoadNow(object sender, 
        LoadItemsEventArgs e)
    {
        int j = e.ItemIndex;
        // You have to estimate the item size
        int estItemSize = 110;

        // Get the optimum page weight for the device
        int wt = 
            Form1.Adapter.Page.Adapter.OptimumPageWeight;
        // Get the number of items per page
        List1.ItemsPerPage = wt / estItemSize;
 
        // Build a section of the array
        ArrayList arr= new ArrayList();
        for (int i = 1; i <= e.ItemCount; i++)
        {
            int v = i + j;
            arr.Add((v.ToString() + " List Item"));
        }

        // Bind the array to the list
        List1.DataSource = arr;
        List1.DataBind();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:Form id="Form1" runat="server" 
        Paginate="true">
        <mobile:TextView ID="TextView1" 
            Runat="server" />
    </mobile:Form>
</body>
</html>
<%@ Page Language="VB" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>
<%@ Import Namespace="System.Security.Permissions" %>

<script runat="server">
    ' A custom list control for illustration
    < _
    AspNetHostingPermission(SecurityAction.Demand, _
        Level:=AspNetHostingPermissionLevel.Minimal), _
    AspNetHostingPermission(SecurityAction.InheritanceDemand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public Class ListControl
        Inherits List

        Public Sub New()
            MyBase.New()
        End Sub

        ' Set a weight for the items
        Protected Overrides ReadOnly _
            Property ItemWeight() As Integer
            Get
                Return 150
            End Get
        End Property
    End Class

    Dim WithEvents List1 As ListControl
    
    Private Sub Page_Load(ByVal sender As Object, _
        ByVal e As EventArgs)

        ' Instantiate the custom control
        List1 = New ListControl()
        List1.ItemCount = 20
        List1.ID = "List1"
        Form1.Controls.Add(List1)

        Form1.ControlToPaginate = List1
    End Sub

    ' Called by the List whenever it needs new items
    Private Sub LoadNow(ByVal sender As Object, _
        ByVal e As LoadItemsEventArgs) _
        Handles List1.LoadItems

        Dim j As Integer = e.ItemIndex
        
        ' You have to estimate the item size
        Dim estItemSize As Integer = 110

        ' Get the optimum page weight for the device
        Dim wt As Integer = _
            Form1.Adapter.Page.Adapter.OptimumPageWeight
        ' Get the number of items per page
        List1.ItemsPerPage = wt / estItemSize
 
        ' Build a section of the array
        Dim arr As New ArrayList()
        For i As Integer = 1 To e.ItemCount
            Dim v As Integer = i + j
            arr.Add((v.ToString() + " List Item"))
        Next

        ' Bind the array to the list
        List1.DataSource = arr
        List1.DataBind()
    End Sub
</script>

<html xmlns="http:'www.w3.org/1999/xhtml" >
<body>
    <mobile:Form id="Form1" runat="server" 
        Paginate="true">
        <mobile:TextView ID="TextView1" 
            Runat="server" />
    </mobile:Form>
</body>
</html>

注釈

値 -1 は、要素の既定の重みを使用する必要があることを示します。 継承クラスは、このプロパティをオーバーライドする必要があります。 このプロパティのオーバーライドの詳細については、「 改ページ処理のサポート」を参照してください。

適用対象

こちらもご覧ください