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