title: How do I keep data in a generic list after postback
body: <p>I am trying to populate a <code>Nested Repeater</code> by databinding it to a <code>Generic List</code>.</p>
  
  <p>The user will be able to add / remove values from this <code>Generic List</code> at will.<br>
  All this is neatly wrapped in an <code>Ajax Update Panel</code>.</p>
  
  <p>I am now having a problem that when the user tries to add values to the <code>Generic List</code>, it only adds ` initial value, then keeps updating that value when they click to add more.</p>
  
  <p>I have a suspicion that its because the <code>Generic List</code> doesn't keel its initial data or something; but I'm really not too sure.</p>
  
  <p>Please can someone help.</p>
  
  <p><strong>Chalenge.cs</strong></p>
  
  <pre><code>public class challenge
  {
      public class Team
      {
          public string TeamName { get; set; } 
      }
      public class Member:Team
      {
          public string Name { get; set; }
      }
  
      //This is just a test, but I cant get a list in a class file to work properly.
      public class ChallengeList
      {
          public List&lt;Member&gt; Member()
          {
              return null;
          }
      }
  }
  </code></pre>
  
  <p><strong>Page.cs</strong></p>
  
  <pre><code>private List&lt;challenge.Member&gt; Members = new List&lt;challenge.Member&gt;();
  
  protected void Page_Load(object sender, EventArgs e)
  {
      if (Page.IsPostBack) return;
  
      lblCurrent.Text = SiteSession.Current.Nickname;
      lblChallenge.Text = Request.QueryString["Challenge"];
  
      //Add the initial teams
      PopulateTeamRepeater();
      AddData();
  }
  
  private List&lt;challenge.Member&gt; AddData()
  {
      Members.Add(
          new challenge.Member
              {
                  Name = SiteSession.Current.Nickname,
                  TeamName = "Team One"
              });
      Members.Add(
              new challenge.Member
                  {
                      Name = Request.QueryString["Challenge"],
                      TeamName = "Team Two"
                  });
  
      return Members;
  }
  
  /// &lt;summary&gt;
  /// Add the selected member to the team
  /// &lt;/summary&gt;
  /// &lt;param name="sender"&gt;&lt;/param&gt;
  /// &lt;param name="e"&gt;&lt;/param&gt;
  protected void drpTeams_SelectedIndexChanged(object sender, EventArgs e)
  {
      Members.Add(
          new challenge.Member
          {
              Name = tbMemberAuto.Text,
              TeamName = drpTeams.SelectedItem.Value
          });
  
  
      PopulateTeamRepeater();
  }
  </code></pre>
  
  <p><strong>UPDATE: Binding of the repeaters (Same page)</strong></p>
  
  <pre><code> /// &lt;summary&gt;
      /// Populates the Team repeater control with the amount of teams the user has selected
      /// &lt;/summary&gt;
      private void PopulateTeamRepeater()
      {
  
  
          ArrayList cArrayList = new ArrayList(); //Main holder
          StringBuilder sb = new StringBuilder(); //Temp holer
  
          try
          {
  
              //Get all team numbers
              foreach (challenge.Member Team in AddData())
              {
                  //Add it to the string builder
                  sb.Append(Team.TeamName + ";");
              }
  
              //Split the string to get the strings (As a temporary holder)
              string[] cs = sb.ToString().Split(';');
  
              //Add the groups (unique) to the next holder
              foreach (string s in cs.Where(s =&gt; !cArrayList.Contains(s)))
              {
                  cArrayList.Add(s);
              }
  
              rptTeam.DataSource = cArrayList;
              rptTeam.DataBind();
          }
          catch (Exception es)
          {
              misc.ChangeInfo(Master.Page, "Error filling teams: " + es.Message, "ui-state-error");
          }
      }
  
  /// &lt;summary&gt;
  /// Populate the Member repeater based on the Team
  /// &lt;/summary&gt;
  /// &lt;param name="sender"&gt;&lt;/param&gt;
  /// &lt;param name="e"&gt;&lt;/param&gt;
  protected void rptTeam_ItemDataBound(object sender, RepeaterItemEventArgs e)
  {
      Repeater rptMembers = (Repeater)e.Item.FindControl("rptMembers");
      Label lblTeam = (Label)e.Item.FindControl("lblTeam");
  
      rptMembers.DataSource = AddData().Where(m =&gt; m.TeamName == lblTeam.Text);
      rptMembers.DataBind();
  }
  </code></pre>