Listing D—IEnumerable binding
//NOTE: this snippet is assumed to be in a codebehind event handler
CollectionClass c = new CollectionClass();
this.ListBox1.DataSource = c;
this.ListBox1.DataTextField = "Description";
this.ListBox1.DataValueField = "ID";
this.ListBox1.DataBind();

class DataClass{
       public string Description{
              get{return description;}
              set{description = value;}
       }
       public int ID{
              get{return id;}
              set{id = value;}
       }
       private string description;
       private int id;
}
class CollectionClass : System.Collections.IEnumerable, System.Collections.IEnumerator{
       private int current;
       private int count;
       private DataClass[] privatedata;
       public CollectionClass(){
              privatedata = new DataClass[10];
              for(int i=0; i<10; i++){
                     privatedata[i]=new DataClass();
                     privatedata[i].ID = i;
                     privatedata[i].Description = "IEnumerable item " + i;
              }
              current = -1;
              count = 10;
       }
       #region Implementation of IEnumerable
       public System.Collections.IEnumerator GetEnumerator() {
              return this;
       }
       #endregion}

       #region Implementation of IEnumerator
       public void Reset() {
              current = -1;
       }
       public bool MoveNext() {
              current++;
              return (current < count);
       }
       public object Current {
              get {
                     return privatedata[current];
              }
       }
       #endregion
}