Note that there are some explanatory texts on larger screens.

plurals
  1. POASP vb.net : How to dynamically change list bound to repeater
    primarykey
    data
    text
    <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="VB" ClassName="ControlCar" %&gt; &lt;script runat="server"&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 = "(m_car Is Nothing)" Else lit_color.Text = "color of Me.m_car is (" &amp; Me.m_car.Color &amp; ")" End If End Sub &lt;/script&gt; &lt;asp:Panel ID="panel" OnLoad="Panel_OnLoad" runat="server"&gt; this is a car&lt;br /&gt; color = &lt;asp:Literal ID="lit_color" runat="server"&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="uc" TagName="ControlCar" Src="myfile.ascx" %&gt; &lt;asp:Repeater ID="id_repeater" runat="server"&gt; &lt;headertemplate&gt; &lt;/headertemplate&gt; &lt;itemtemplate&gt; &lt;uc:ControlCar id="ControlCarTemplate" Car=&lt;%# CType(Container.DataItem, Car)%&gt; runat="server" /&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 = "red" 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 = "blue" 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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload