Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieve object from an arraylist with a specific element value
    primarykey
    data
    text
    <p>I have a class with some attributes. For example class person with name, age, gender and so on as attribute.</p> <p>People fill out a form, with among other things their gender which is a dropdownlist, they submit it and the person is added to the arraylist.</p> <p>What I need is a function by clicking a button to display all the persons who chose Female as gender.</p> <p>Can somebody please help me? I have tried and searched for the right answer for days now and getting a little desperat now.</p> <p>Many thanks!!!</p> <p>Olaf</p> <p>This is my .cs code</p> <pre><code> public class Person { private string name; private string artistname; private string address; private double number; private double zip; private string day; private string gender; public Person(string name, string artistname, string address, double number, double zip, string day, string gender) { this.name = name; this.artistname = artistname; this.address = address; this.number = number; this.zip = zip; this.day = day; this.gender = gender; } public override string ToString() { string newPerson = name + " aka " + artistname + " lives on " + address + " " + number + " " + zip + " " + day + "Gender: " + gender; return newPerson; } } </code></pre> <p>And this is my .aspx code:</p> <pre><code>public partial class Index : System.Web.UI.Page { static ArrayList personArrayList; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { personArrayList = new ArrayList(); } } protected void btnSubmit_Click(object sender, EventArgs e) { Person p = new Person(txtName.Text, txtArtistName.Text, txtAddress.Text, Convert.ToDouble(txtNumber.Text), Convert.ToDouble(txtPostal.Text), Convert.ToString(dropdownDay.Text), Convert.ToString(dropdownGender.Text)); personArrayList.Add(p); } protected void btnShowAll_Click(object sender, EventArgs e) { ListBoxShow.Items.Clear(); for (int i = 0; i &lt; personArrayList.Count; i++) { ListBoxShow.Items.Add(personArrayList[i].ToString()); } } protected void btnShowGentle_Click(object sender, EventArgs e) { ListBoxShow.Items.Clear(); } protected void btnShowLadies_Click(object sender, EventArgs e) { ListBoxShow.Items.Clear(); for (int i = 0; i &lt; personArrayList.Count; i++) { if (personArrayList[i].gender = "Female") { } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload