TextView.LoadItems Event
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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.
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
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>
<%@ 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>
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.