I am using the following code to store a person’s information from a grid view row in a list:
public class PlayerInfo
{
public string FirstName { get; set; }
public string Email { get; set; }
public string DaysLeft { get; set; }
}
protected void btn_Click(object sender, EventArgs e)
{
List<PersonInfo> person_list = new List<PersonInfo>();
foreach (GridViewRow row in my_gridview.Rows)
{
CheckBox cb = (CheckBox)(row.Cells[2].FindControl("CheckBox"));
if (cb.Checked)
{
person_list.Add(new PlayerInfo() {FirstName=row.Cells[0].Text,Email=row.Cells[2].Text,DaysLeft=row.Cells[5].Text});
}
else
{
}
}
etc etc..
}
So if I try and output person_list[0] this will not work as there are three items associated to each point in the list, so position 0 in the list contains the first name, email and days left. I can see the items are being stored properly when debugging in visual studio.
How would I retrieve each item individually from this list? For example being able to set the values to variables in a loop, so the email address would be assigned to an email variable, the first name to another etc? I have only ever dealt with normal arrays and have never come across a hierarchical list before.
Thanks in advance.
Iterate it using for like this