TextView.LoadItems 事件

定义

在控件自定义分页且需要更多数据时发生。 此 API 已废弃不用。 有关如何开发 ASP.NET 移动应用程序的信息,请参阅 移动应用 & 具有 ASP.NET 的网站

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 Web 窗体页代码模型

<%@ 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>

注解

控件自定义分页时,不会显式绑定控件。 分页后,控件将引发此事件,指示需要数据的哪一部分。 应用程序可以处理此事件,并将控件与所需的数据绑定。

适用于

另请参阅