我有一个具有一些属性的类。例如以姓名、年龄、性别等为属性的类人。
人们填写表格,除其他事项外,他们的性别是一个下拉列表,他们提交表格并将此人添加到数组列表中。
我需要的是一个功能,通过单击一个按钮来显示所有选择女性作为性别的人。
有人能帮帮我吗?我已经尝试并寻找正确的答案好几天了,现在有点绝望了。
非常感谢!!!
奥拉夫
这是我的 .cs 代码
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;
}
}
这是我的 .aspx 代码:
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 < 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 < personArrayList.Count; i++)
{
if (personArrayList[i].gender = "Female")
{
}
}
}
}