Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8874433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:43:12+00:00 2026-06-14T18:43:12+00:00

I would like to puplate a list dynamically, and bind it to an asp

  • 0

I would like to puplate a list dynamically, and bind it to an asp repeater which use a custom control.

Here is my custom control (.acsx file) :

<%@ Control Language="VB" ClassName="ControlCar" %>
<script runat="server">
    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 (" & Me.m_car.Color & ")"
        End If
    End Sub
    
</script>

<asp:Panel ID="panel" OnLoad="Panel_OnLoad" runat="server">
    this is a car<br />
    color = <asp:Literal ID="lit_color" runat="server"></asp:Literal><br />
    <br />
</asp:Panel>

So I create a repeater in my aspx file :

<%@ Register TagPrefix="uc" TagName="ControlCar" Src="myfile.ascx" %>
<asp:Repeater ID="id_repeater" runat="server">
    <headertemplate>
    </headertemplate>
    <itemtemplate>  
    <uc:ControlCar id="ControlCarTemplate" Car=<%# CType(Container.DataItem, Car)%> runat="server" />
    </itemtemplate>
</asp:Repeater>    

List to populate repeater is declared :

Private Shared list_cars As ArrayList

On LoadPage event, I add one item in list :

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()

When I display page, I correctly see this :

this is a car

color = color of Me.m_car is (red)

OK, it works fine on load page event

But now, I want add item on button clic event defined here :

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

On click event, I see now that :

this is a car

color = (m_car Is Nothing)

this is a car

color = (m_car Is Nothing)

It doesn’t work, I think Container.DataItem is Nothing value, it is good instance only when loading page

I don’t know how to fix it, any help ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:43:13+00:00Added an answer on June 14, 2026 at 6:43 pm

    On your Page_Load, use Not Page.IsPostBack

    If Not Page.IsPostBack Then
    
        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()
    
    End If
    

    Whenever you click the button, a postback occurs and the list is overwritten with list_cars = New ArrayList() in Page_Load.

    And also, asp.net is not windows application, you cannot add item to existing list because of the postback unless you hold the list in Session or ViewState

    In your codebehind of your page add this property

    Public Property list_cars As ArrayList
    
        Get
           If ViewState("list_cars") IsNot Nothing Then
              Dim list As ArrayList = CType(ViewState("list_cars"), ArrayList)
              return list
           End If
    
           return Nothing 'or return an empty list
        End Get
    
        Set
             ViewState("list_cars") = value
        End Set
    
    End Property
    

    To use this in your page:

    Dim updatedList As ArrayList = list_cars
    updatedList.Add(car)
    
    list_cars = updatedList
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

would like your comments. Eg: When user first visit www.testing.com/productdetailpage.asp I will use caching-
Would like to know which library (open source preferable) should I use to create
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
Would like to know how to integarate cruise control with maven? Cruise Control comes
Would like to write a script to detect the file size of the target
Would like to build a list of indices into a 2 dimensional bool_ array,
would like to know which Font is the thinnest in Java. I have limited
Would like to get a list of all packages available on CRAN to the
Would like suggestions on quick and easy error handling for asp.net mvc web application.
Would like to fopen() the latest file in a directory (with naming scheme file1.txt,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.