共用方式為


TextView.LoadItems 事件

定義

控制項已自訂分頁且需要更多資料時會發生。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites

public:
 event System::Web::UI::MobileControls::LoadItemsEventHandler ^ LoadItems;
[System.ComponentModel.Browsable(false)]
public event System.Web.UI.MobileControls.LoadItemsEventHandler LoadItems;
[<System.ComponentModel.Browsable(false)>]
member this.LoadItems : System.Web.UI.MobileControls.LoadItemsEventHandler 
Public Custom Event LoadItems As LoadItemsEventHandler 

事件類型

屬性

範例

下列程式代碼範例示範如何建立自定義分頁,並呼叫 LoadItems 方法來載入每個頁面指定的項目數。

注意

下列程式代碼範例會使用單一檔案程式代碼模型,如果直接複製到程式代碼後置檔案,可能無法正常運作。 此程式代碼範例必須複製到擴展名為 .aspx的空文本檔。 如需詳細資訊,請參閱 ASP.NET 網頁代碼模型

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

<script runat="server">
    // Returns an array of Boolean values
    private bool[] TestPrimes(int from, int howMany)
    {
        // Test a range of numbers to determine which are prime.
        bool[] isPrime = new bool[howMany];

        int endAt = from + howMany - 1;
        for (int i = from; i < endAt; i++)
        {   // Set a default value of true
            isPrime[i - from] = true;

            int sqrt = (int)Math.Sqrt(i);
            for (int factor = 2; factor <= sqrt; factor++)
            {
                if ((i % factor) == 0)
                {   // Set value as false
                    isPrime[i - from] = false;
                    break;
                }
            }
        }
        return isPrime;
    }

//<Snippet2>
    protected void Page_Load(object sender, EventArgs args)
    {
        if (!IsPostBack)
        {
            Primes.ItemCount = 2000;
            Primes.ItemsPerPage = 20;
            form1.ControlToPaginate = Primes;
        }
    }
//</Snippet2>

    protected void Primes_OnLoadItems(object sender, LoadItemsEventArgs args)
    {
        StringBuilder StrBldr = new StringBuilder();
        Primes.Text = "";

        // Start the list at 2.
        int startNumber = args.ItemIndex + 2;
        bool[] isPrime;
        isPrime = TestPrimes(startNumber, args.ItemCount);

        for (int i = 0; i < args.ItemCount; i++)
        {
            string message;
            if (isPrime[i])
                message = String.Format("<b>{0} is prime</b>", 
                    i + startNumber);
            else
                message = String.Format("<b>{0}</b> is not prime", 
                    i + startNumber);

            StrBldr.Append(message);
            StrBldr.Append("<br />");
        }
        Primes.Text = StrBldr.ToString();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="form1" runat="server" paginate="true">
        <mobile:TextView id="Primes" runat="server" 
            OnLoadItems="Primes_OnLoadItems" />
    </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" %>

<script runat="server">
    ' Returns an array of Boolean values
    Private Function TestPrimes(ByVal [from] As Integer, ByVal howMany As Integer) As Boolean()
        ' Test a range of numbers to determine which are prime.
        Dim isPrime(howMany - 1) As Boolean

        Dim endAt As Integer = From + howMany - 1
        For i As Integer = From To endAt - 1
            isPrime(i - From) = True

            Dim sqrt As Integer = CInt(Fix(Math.Sqrt(i)))
            For factor As Integer = 2 To sqrt
                If (i Mod factor) = 0 Then
                    isPrime(i - From) = False
                    Exit For
                End If
            Next factor
        Next i
        Return isPrime
    End Function

'<Snippet2>
    Protected Sub Page_Load(ByVal sender As Object, ByVal args As EventArgs)
        If Not IsPostBack Then
            Primes.ItemCount = 2000
            Primes.ItemsPerPage = 20
            form1.ControlToPaginate = Primes
        End If
    End Sub
'</Snippet2>

    Protected Sub Primes_OnLoadItems(ByVal sender As Object, ByVal args As LoadItemsEventArgs)
        Dim StrBldr As New StringBuilder()
        Primes.Text = ""

        ' Start the list at 2.
        Dim startNumber As Integer = args.ItemIndex + 2
        Dim isPrime() As Boolean
        isPrime = TestPrimes(startNumber, args.ItemCount)

        For i As Integer = 0 To args.ItemCount - 1
            Dim message As String
            If isPrime(i) Then
                message = String.Format("<b>{0} is prime</b>", i + startNumber)
            Else
                message = String.Format("<b>{0}</b> is not prime", i + startNumber)
            End If

            StrBldr.Append(message)
            StrBldr.Append("<br />")
        Next i
        Primes.Text = StrBldr.ToString()
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="form1" runat="server" paginate="true">
        <mobile:TextView id="Primes" runat="server" 
            OnLoadItems="Primes_OnLoadItems" />
    </mobile:form>
</body>
</html>

備註

當控件是自定義編頁時,您不會明確系結控件。 分頁之後,控件會引發這個事件,指出需要哪些部分的數據。 應用程式可以處理此事件,並將控件與必要的數據系結。

適用於

另請參閱