作者mmfily (mm)
看板C_Sharp
标题[问题] LIST<T>问题...
时间Wed Oct 3 19:47:55 2012
想请问一下,我要每一次按下确认的时候把DropDownList中的值存下来
程式码如下:
在一开始的地方 有先宣告了List<string> name = new List<string>();
protected void Button1_Click(object sender, EventArgs e)
{
string rec = "";
for (int i = 0; i < DropDownList1.Items.Count; i++)
{
if (DropDownList1.Items[i].Selected)
{
rec = DropDownList1.Items[i].Value.ToString();
}
}
proglist.Text = proglist.Text + "<p>" + rec;
name.Add(rec);
string mm = "";
foreach (string str in name)
{
mm += "\n" + str;
}
Label19.Text = mm;
}
现在执行後的结果 Label19只会显示我最後按下的DropDownList的值,前面的都被更新
掉了..
例如:我在DropDownList中放有A、B、C三个,第一次按下的时候是显示A,第二次就变成
B了,不是应该要出现A B吗...
感谢各位看到这里,要麻烦指教一下…
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.163.212.165
※ 编辑: mmfily 来自: 118.163.212.165 (10/03 19:50)
1F:→ ideaup:{ rec=; proglist.Text=; } 10/04 09:44