Re: [問題] LIST<T>問題...

看板C_Sharp (C#)作者 (Zac)時間12年前 (2012/10/03 22:38), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/3 (看更多)
※ 引述《mmfily (mm)》之銘言: : 想請問一下,我要每一次按下確認的時候把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嗎... : 感謝各位看到這裡,要麻煩指教一下… 你是在哪裡宣告 List<string> name = new List<string>(); 我的解法是 protected void Button1_Click(object sender, EventArgs e) { string value = DropDownList1.SelectedValue; Label19.Text += string.format("<p>{0]", value); } <p>你是想用HTML <p></p> 嗎? 至於我猜測你是想把 value收集起來, 那之後去讀Label19.Text去作處理就好了! 以上憑印象打,有錯請多包含 -- http://blog.bambi.tw/ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 36.224.45.96
文章代碼(AID): #1GR4t8Mf (C_Sharp)
討論串 (同標題文章)
本文引述了以下文章的的內容:
以下文章回應了本文
完整討論串 (本文為第 2 之 3 篇):
文章代碼(AID): #1GR4t8Mf (C_Sharp)