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

The Archive Base Latest Questions

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

I am trying to create a very simple ASP.NET page that allows a user

  • 0

I am trying to create a very simple ASP.NET page that allows a user to enter student data. When the form is submitted, the List of student objects is updated and the Repeater (which is databound to the list) reflects the new data. The user should be able to keep adding new students.

Mine fails to perform. I have no idea why. I have tried changing the postback and databinding methods many times.

   /*
     * Student class representing a real-life student.
     */
    public class Student
    {

        /* Override default constructor */
        public Student(string first, string last, string studentid, string program, string option)
        {
            FName = first;
            LName = last;
            STID = studentid;
            Program = program;
            Option = option;
        }

        /* Property for the student's first name */
        public string FName
        {
            set; get;
        }

        /* Property for the student's last name */
        public string LName 
        {
            set; get;         
        }

        /* Property for the student ID */
        public string STID
        {
            set; get;
        }

        /* Property for the program of study */
        public string Program
        {
            set; get;
        }

        /* Property for the option within the program of study */
        public string Option
        {
            set; get;
        }

    }

    /* Class for the web form UI */
    public partial class _Default : System.Web.UI.Page
    {

        /* List of students to be displayed in the repeater control */
        private List<Student> myStudents;

        protected void Page_Load(object sender, EventArgs e)
        {

            myStudents = new List<Student>();



            /* Check postback value when the page loads - this is the first time */
            if (IsPostBack == false)
            {
                /* Bind the Collection to the Repeater control */
                Label1.Text = "" + myStudents.Count;
                Repeater1.DataSource = myStudents;
                Repeater1.DataBind();
            }


        }

        /* 
         * Submit button clicked to submit the form.
         */
        protected void Button2_Click(object sender, EventArgs e)
        {

            /* The forum has passed all of the validation rules for this case and we can add a new student to the list */
             if(Page.IsValid) {

                /*if its valid then create a new student object to put into the list of students
                  get the data from POST*/
                 myStudents.Add(new Student(FNameTextBox.Text, LNameTextBox.Text, SIDTextBox.Text, POSDropDownList.SelectedItem.Text, POListBox.SelectedItem.Text));

                 Label1.Text = "" + myStudents.Count;


              }

        }
    }

Here is the code for the Repeater:

<asp:Repeater ID="Repeater1" runat="server">
  <HeaderTemplate>
         <table border="1">
            <tr>
               <td><b>First Name</b></td>
               <td><b>Last Name</b></td>
               <td><b>Student ID</b></td>
               <td><b>Program</b></td>
               <td><b>Option</b></td>
            </tr>
      </HeaderTemplate>

      <ItemTemplate>
         <tr>
            <td> <%# DataBinder.Eval(Container.DataItem, "FName")%> </td>
            <td> <%# DataBinder.Eval(Container.DataItem, "LName") %> </td>
            <td> <%# DataBinder.Eval(Container.DataItem, "STID")%> </td>
            <td> <%# DataBinder.Eval(Container.DataItem, "Program") %> </td>
            <td> <%# DataBinder.Eval(Container.DataItem, "Option") %> </td>
         </tr>
      </ItemTemplate>

      <AlternatingItemTemplate>
        <tr bgcolor="#e8e8e8">
          <td> <%# DataBinder.Eval(Container.DataItem, "FName")%> </td>
            <td> <%# DataBinder.Eval(Container.DataItem, "LName") %> </td>
            <td> <%# DataBinder.Eval(Container.DataItem, "STID")%> </td>
            <td> <%# DataBinder.Eval(Container.DataItem, "Program") %> </td>
            <td> <%# DataBinder.Eval(Container.DataItem, "Option") %> </td>
        </tr>
       </AlternatingItemTemplate>

      <SeparatorTemplate>
        <tr>
        <td colspan="5"><hr /></td>
        </tr>
      </SeparatorTemplate>

      <FooterTemplate>
         </table>
      </FooterTemplate>
</asp:Repeater>
  • 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-12T01:35:16+00:00Added an answer on June 12, 2026 at 1:35 am

    I have refactored your code, now it should work

    /* Class for the web form UI */
    public partial class _Default : System.Web.UI.Page
    {
    
        /* List of students to be displayed in the repeater control */
        private List<Student> myStudents = new List<Student>();
    
        protected void Page_Load(object sender, EventArgs e){
    
            /* Check postback value when the page loads - this is the first time */
            if (IsPostBack == false){
              this.bindRepeater();
            }
        }
    
     private void bindRepeater(){
      /* Bind the Collection to the Repeater control */
                Repeater1.DataSource = myStudents;
                Repeater1.DataBind();
                Label1.Text = "" + myStudents.Count;
                }
    
        /* 
         * Submit button clicked to submit the form.
         */
        protected void Button2_Click(object sender, EventArgs e)
        {
    
            /* The forum has passed all of the validation rules for this case and we can add a new student to the list */
             if(Page.IsValid) {
    
                /*if its valid then create a new student object to put into the list of students
                  get the data from POST*/
                 myStudents.Add(new Student(FNameTextBox.Text, LNameTextBox.Text, SIDTextBox.Text, POSDropDownList.SelectedItem.Text, POListBox.SelectedItem.Text));
                 this.bindRepeater();
    
    
              }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a very simple page that contains a container, a header,
I am trying to create an ASP.NET page that connects to QuickBooks Online Edition,
I'm new to ASP.NET MVC and I'm trying to create a very simple blog
I'm trying to create a very simple chat application in Flex/.Net using FluorineFX but
I am trying to create a very simple chat window that simply has the
In my Java app I am trying to create a very simple form with
As of right now I am trying to create an ASP.NET page which will
I'm trying to create a very simple contentEditable div input. However, any way that
I am trying to create a very simple form with a little bit of
I am trying to create a very simple Newsletter sign up that I can

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.