ItemWeight, propriété (PagedControl)
Accède au poids approximatif d'un élément unique du contrôle.
protected virtual int ItemWeight {
get
}
Notes
La valeur –1 indique que le poids par défaut de l'élément doit être utilisé. La classe qui hérite doit se substituer à cette propriété. Pour plus d'informations sur la substitution de cette propriété, consultez Prise en charge de la pagination.
Exemple
L'exemple suivant crée et utilise un contrôle personnalisé. Il montre comment substituer la propriété ItemWeight d'une classe List pour spécifier le nouveau poids d'un contrôle.
' *** 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>
Voir aussi
PagedControl, classe