0
我正在尝试使用List
来填充DropDownList
。用户输入球的名称及其重量,然后添加到列表框中。在默认的网页我有:使用列表填充DropDownList
List<Ball> myBall;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
myBall = new List<Ball>();
Session["listSession"] = myBall;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Clear();
Ball f = new Ball(TbxName.Text, int.Parse(TbxWeight.Text));
myBall= (List<Ball>)Session["listSession"];
myBall.Add(f);
foreach (var item in myBall)
{
ListBox1.Items.Add(item.getBallInfo());
}
,并在我的球类:
public Ball(string n, int w)
{
name = n;
weight = w;
}
public string getBallInfo()
{
string s;
if (weight > 5)
{
s = name + " is huge"
}
else
{
s = name + " is small"
}
我如何,与DropDownList
另一个类,从默认类球名称来填充呢?
感谢您的时间和回答 – user2158735
不客气:) – Luaan