Share via


ItemWeight Property (PagedControl)

Accesses the approximate weight of a single item in the control.

protected virtual int ItemWeight {
   get
}

Remarks

A value of –1 indicates that the default weight for the element must be used. The inheriting class must override this property. For further information about overriding this property, see Pagination Support.

Example

The following example creates and uses a custom control. The example demonstrates how to override the ItemWeight property of a List class to specify a new control weight.

' *** 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>

See Also

Applies to: PagedControl Class