Proprietà ItemWeight (PagedControl)

Accede al peso approssimativo di un singolo elemento nel controllo.

protected virtual int ItemWeight {
   get
}

Osservazioni

Il valore –1 indica che è necessario utilizzare il peso predefinito dell'elemento. La classe che eredita deve eseguire l'override della proprietà. Per ulteriori informazioni sull'override di questa proprietà, vedere Supporto per l'impaginazione.

Esempio

Nell'esempio riportato di seguito viene creato e utilizzato un controllo personalizzato. L'esempio mostra come eseguire l'override della proprietà ItemWeight di una classe List per specificare un nuovo peso per il controllo.

' *** Custom Control ***
' Create my own list control so that I can override the ItemWeight 
' property and give it a higher value.
Public Class MyList : Inherits System.Web.UI.MobileControls.List

    Private _myItemWeight As Integer

    Public Sub New()

        MyBase.New()
        _myItemWeight = ItemWeight

    End Sub

    'Give this control a weight of 400 overriding its default value.
    Protected Overrides ReadOnly Property ItemWeight() As Integer
        Get
            Return 400
        End Get
    End Property

    'ItemWeight is not accessible through the protected property
    'so using my own property to obtain this value.
    Public ReadOnly Property MyItemWeight() As Integer
        Get
            Return _myItemWeight

        End Get
    End Property

End Class

'*** Using the Custom Control ***

<Script Language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Obtain the amount of lines that this device adapter can display.
        Dim pageWeight As Integer = 
        MyForm1.Adapter.Page.Adapter.OptimumPageWeight

        Dim amountOfItemsToDisplay As Integer = pageWeight / 
        MyList1.MyItemWeight

        ' Display the amount of lines that will display on each page after 
        ' pagination.
        MyList1.Items.Add(amountOfItemsToDisplay.ToString())
    End Sub
</Script>

   <MOBILE:FORM id="MyForm1" runat="server" Paginate="True">
      <MyListControls:MyList id="MyList1" runat="server"></MyListControls:MyList>
   </MOBILE:FORM>

[C#]

//*** Custom Control ***
namespace NormsControls.CustomListControl
{

public class ListControl : System.Web.UI.MobileControls.List
{
   public int _myItemWeight;

   public ListControl():
      base()
   {
      _myItemWeight = ItemWeight;
   }
    
   // Give this control a weight of 400 overriding its default value.
   override protected int ItemWeight
   {
      get
      {
         return 400;
      }
   }

   //ItemWeight is not accessible through the protected property.
   //so using my own property to obtain this value.
   public int MyItemWeight
   {
      get
      {
         return _myItemWeight;
      }
         
   }
    
}

    
}
//*** Using the Custom Control ***

private void Page_Load(object sender, System.EventArgs e)
{
   //Obtain the amount of lines that this device adapter can display.
         
   int pageWeight = Form1.Adapter.Page.Adapter.OptimumPageWeight;

   int amountOfItemsToDisplay = pageWeight / MyList1.MyItemWeight;

   //Display the amount of lines that will display on each page after 
   //pagination.
   MyList1.Items.Add(amountOfItemsToDisplay.ToString());   

}
   <mobile:Form id="Form1" runat="server">
      <NormsTest:ListControl id="MyList1"  
       runat="server"></NormsTest:ListControl>
   </mobile:Form>

Vedere anche

Classe PagedControl