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 9131471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:08:48+00:00 2026-06-17T08:08:48+00:00

I have created a class that can contain several instances of an object, all

  • 0

I have created a class that can contain several instances of an object, all of the data is stored in the session. I won’t know how many instances until run-time. What is the best approach for displaying this dynamic data. Im using aspx with code behind, so I assume it needs to happen in the load sub.

In case it helps, heres the class, its in VB but answers in c# are fine:

Imports System.Web.HttpContext

Public Class Student

    Public Property SchoolId As Integer
    Public Property Grade As Integer
    Public Property StudentName As String


    Public Sub AttachToSession(StudentToBeAdded As Student)

        Dim StudentList As New List(Of Student)

        If (Current.Session("student") Is Nothing) Then

            StudentList.Add(StudentToBeAdded)
            Current.Session("student") = StudentList

        Else

            StudentList = Current.Session("student")
            StudentList.Add(StudentToBeAdded)
            Current.Session("student") = StudentList

        End If

    End Sub

End Class
  • 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-17T08:08:49+00:00Added an answer on June 17, 2026 at 8:08 am

    Or, if you want a custom look and feel, you could try something like this (in your aspx page):

    <% For Each l_student As Student In CType( Session( "student" ), List(Of Student) ) %>
        <div>
            <p>Name: <%= l_student.StudentName %></p>
            <p>Grade: <%= l_student.Grade %></p>
        </div>
    <% Next %>
    

    This would create one ‘div’ element for each item in your student collection.

    See: Introduction to ASP.NET inline expressions in the .NET Framework

    You might be better off creating a shared property in your student class though:

    Public Shared ReadOnly Property Students As List(Of Student)
        Get
            Dim l_studentList As List(Of Student) = TryCast( Current.Session("student"), List(Of Student) )
            If l_studentList Is Nothing Then
                l_studentList = New List(Of Student)
                Current.Session("student") = l_studentList
            End If
    
            Return l_studentList
        End Get
    End Property
    

    Then your aspx would be:

    <% For Each l_student As Student In Student.Students %>
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that I can have many instances of. Inside it creates
I have a C++ class that I need to create several instances of in
I have created a class that will manage connection and commands, I named it
Currently I have created a ABCFactory class that has a single method creating ABC
I have created a button CSS class that uses background images with different positions
I have created a custom collection class that I am trying to bind to
I have Xcode 4.3 and that class doesn't use ARC. I have created a
I have created a service class for my network connection so that my app
I have a binary tree class that is created with a root node and
I have created a gem that adds a new method to the class ActiveRecord::Base.

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.