title: ASP vb.net : How to dynamically change list bound to repeater
body: <p>I would like to puplate a list dynamically, and bind it to an asp repeater which use a custom control.</p>
  <p>Here is my custom control (.acsx file) :</p>
  <pre><code>&lt;%@ Control Language=&quot;VB&quot; ClassName=&quot;ControlCar&quot; %&gt;
  &lt;script runat=&quot;server&quot;&gt;
      Private m_car As Car = Nothing
      Public Property Car() As Car
          Get
              Car= m_car
          End Get
          Set(ByVal value As Car)
              m_car = value
          End Set
      End Property
      
      Protected Sub Panel_OnLoad(ByVal sender As Object, ByVal e As System.EventArgs)
          If Me.m_car Is Nothing Then
              lit_color.Text = &quot;(m_car Is Nothing)&quot;
          Else
              lit_color.Text = &quot;color of Me.m_car is (&quot; &amp; Me.m_car.Color &amp; &quot;)&quot;
          End If
      End Sub
      
  &lt;/script&gt;
  
  &lt;asp:Panel ID=&quot;panel&quot; OnLoad=&quot;Panel_OnLoad&quot; runat=&quot;server&quot;&gt;
      this is a car&lt;br /&gt;
      color = &lt;asp:Literal ID=&quot;lit_color&quot; runat=&quot;server&quot;&gt;&lt;/asp:Literal&gt;&lt;br /&gt;
      &lt;br /&gt;
  &lt;/asp:Panel&gt;
  </code></pre>
  <p>So I create a repeater in my aspx file :</p>
  <pre><code>&lt;%@ Register TagPrefix=&quot;uc&quot; TagName=&quot;ControlCar&quot; Src=&quot;myfile.ascx&quot; %&gt;
  &lt;asp:Repeater ID=&quot;id_repeater&quot; runat=&quot;server&quot;&gt;
      &lt;headertemplate&gt;
      &lt;/headertemplate&gt;
      &lt;itemtemplate&gt;  
      &lt;uc:ControlCar id=&quot;ControlCarTemplate&quot; Car=&lt;%# CType(Container.DataItem, Car)%&gt; runat=&quot;server&quot; /&gt;
      &lt;/itemtemplate&gt;
  &lt;/asp:Repeater&gt;    
  </code></pre>
  <p>List to populate repeater is declared :</p>
  <pre><code>Private Shared list_cars As ArrayList
  </code></pre>
  <p>On LoadPage event, I add one item in list :</p>
  <pre><code>If IsPostBack Then
      Return
  End If
  
  list_cars = New ArrayList()
  Dim car As Car = New Car
  car.Color = &quot;red&quot;
  list_cars .Add(car)
  id_repeater.DataSource = list_cars 
  id_repeater.DataBind()
  </code></pre>
  <p>When I display page, I correctly see this :</p>
  <blockquote>
  <p>this is a car</p>
  <p>color = color of Me.m_car is (red)</p>
  </blockquote>
  <p><strong>OK, it works fine on load page event</strong></p>
  <p>But now, I want add item on button clic event defined here :</p>
  <pre><code>Sub OnClickAdd(ByVal sender As Object, ByVal e As System.EventArgs)
      Dim car = New Car
      car.Color = &quot;blue&quot;
      list_cars.Add(car)
      id_repeater_products.DataSource = list_cars
      id_repeater_products.DataBind()
  End Sub
  </code></pre>
  <p>On click event, I see now that :</p>
  <blockquote>
  <p>this is a car</p>
  <p>color = (m_car Is Nothing)</p>
  <p>this is a car</p>
  <p>color = (m_car Is Nothing)</p>
  </blockquote>
  <p><strong>It doesn't work, I think Container.DataItem is Nothing value, it is good instance only when loading page</strong></p>
  <p>I don't know how to fix it, any help ?</p>