Classe ObjectListDataBindEventArgs

Rende disponibili i dati per l'evento ItemDataBind di un controllo ObjectList.

public class System.Web.UI.MobileControls.ObjectListDataBindEventArgs : 
   System.Object.EventArgs

Osservazioni

L'evento ItemDataBind può essere utilizzato da una classe ereditata o da un gestore eventi ereditato per eseguire associazioni a dati complessi.

Esempio

In questo esempio, l'evento ItemdataBind chiama la funzione confirmBound definita dall'utente. Uno degli argomenti della funzione è ObjectListDataBindEventArgs. Di tale argomento viene eseguito il cast come tipo di libro. In questo modo è possibile accedere alle relative proprietà, ad esempio il nome e l'autore del libro.

<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" 
   Language="c#" %>

<script Language="c#" runat="server">

class Book
{
   private String _BookName, _Author, _InStock;
   
   public Book(String BookName, String Author, String InStock) 
   { 
      _BookName = BookName; 
      _Author = Author;
      _InStock = InStock;
   }

   public String BookName { get { return _BookName; } }
   public String Author { get { return _Author; } }
   public String InStock { get { return _InStock; } }
}

public void Page_Load(Object sender, EventArgs e)
{
   // Create and fill array.
   ArrayList arr = new ArrayList();
   arr.Add (new Book ("Sushi, Anyone?", "O'Leary", "Yes"));
   arr.Add (new Book ("Secrets of Silicon Valley", "Dull", "No"));
   arr.Add (new Book ("Net Etiquette", "Locksley", "Yes"));
   arr.Add (new Book ("The Gourmet Microwave", "Ringer", "No"));

   // Associate and bind the array to the ObjectList object.
   ObjectList1.DataSource = arr;
   ObjectList1.DataBind ();

   // Override autogeneration.
   ObjectList1.LabelField = "BookName";
}

void confirmBound(object sender, ObjectListDataBindEventArgs e)
{
   // The event has been raised at time of data binding.
   Label1.Text = "Data bound to an ObjectList object.";

   // Use the ListItem property of the ObjectListDataBindEventArgs class
   // to return the book's name.
   Label2.Text = "Book Name: " +
      e.ListItem["BookName"];

   // You can access the same item through the DataItem property of the
   // ObjectListDataBindEventArgs class.
   Label3.Text = "Author : " + ((Book)(e.DataItem)).Author;
}
</script>

<mobile:Form runat="server" id="Form1" >
   <mobile:ObjectList runat="server" id="ObjectList1" 
      OnItemDataBind="confirmBound" >
   </mobile:ObjectList>
   <mobile:Label runat="server" id="Label1" />
   <mobile:Label runat="server" id="Label2" />
   <mobile:Label runat="server" id="Label3" />
</mobile:Form>

Requisiti

Spazio dei nomi: System.Web.UI.MobileControls

Assembly: System.Web.Mobile