Edit

Share via


TextView.LoadItems Event

Definition

Occurs when a control is custom-paginated and needs more data. This API is obsolete. For information about how to develop ASP.NET mobile applications, see Mobile Apps & Sites with ASP.NET.

[System.ComponentModel.Browsable(false)]
public event System.Web.UI.MobileControls.LoadItemsEventHandler LoadItems;

Event Type

Attributes

Examples

The following code example demonstrates how to create custom pagination and call the LoadItems method to load a specified number of items per page.

Note

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information, see ASP.NET Web Forms Page Code Model.

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

Remarks

When control is custom-paginated, you do not explicitly bind the control. After pagination, the control raises this event, indicating what part of the data is required. The application can handle this event and bind the control with the required data.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also