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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:40:05+00:00 2026-05-11T18:40:05+00:00

If I have a List < Person > where person is defined by the

  • 0

If I have a List < Person > where person is defined by the class

class Person
{
   string Forename
   {
      get;set;
   }
   string Surname
   {
      get; set;
   }
}

And I bind it to an asp repeater control that looks like this:

<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
        <asp:Label ID="lblForename" runat="server" Text="Forname" AssociatedControlID="txtForename" />
        <asp:TextBox ID="txtForename" runat="server" Text='<%# ((Person)Container.DataItem).Forename %>' />
        <br />
        <asp:Label ID="lblSurname" runat="server" Text="Forname" AssociatedControlID="txtSurname" />
        <asp:TextBox ID="txtSurname" runat="server" Text='<%# ((Person)Container.DataItem).Surname %>' />
        <br />
    </ItemTemplate>
</asp:Repeater>

What is the best way to get the data that the user types in back into the objects?

I thought that the whole point of data binding was that this was effectively handled for you, but when I inspect the Repeater1.Items collection, there are no changes made. Do I have to write code to do something along the lines of

//This is only intended to be pseudo code
for each item in Repeater1.Items
    ((Person)item.DataItem).Forename = item.FindControl("txtForname").Text;
end for

If that is the case, why is the DataItem property always empty?

Additional info:

I am already calling code the the effect of

this.Repeater1.DataSource =  this.PersonList;
this.Repeater1.DataBind();

I’ve tried using Bind("Forename"), but this doesn’t seem to bring the info from the TextBox back into the object, do I have to do this manually?

  • 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-05-11T18:40:05+00:00Added an answer on May 11, 2026 at 6:40 pm

    The simple answer is that the Repeater control does not support the kind of two-way databinding that you are looking for. On top of that, the DataItem property is only used during the creation of the repeater item, and after the ItemDataBound event, it is set to nothing. So you cannot use that property to get the original object you used when creating the specific repeater item after postback (as you are doing in your pseudocode).

    You will have to loop through the repeater items, as you suggested (make sure to check that the item is of ListItemType.Item or AlternatingItem before doing anything) and then extract the values from the textboxes and use them in an update.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these classes: public class Person { public int Id{ get; set ;}
I have a list of Persons inside a Company Class. public class Company{ IList<Person>
I've been trying to use a List<> of a Model.Person that I have inside
I have a simple class as defined below: public class Person { int _id;
I have a Person class that inherits PersonBase and this second class inherits EntityBase
I have a Person class that inherits EntityBase : public class Person : EntityBase
I have a List<Person> objects where person is defined like so public Person {
I have a list of objects with the following basic structure: class Person {
I have a list of person objects which I want to send in response
I have a list of people with Person objects with getName() and getYearOfBirth() methods.

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.