Re: [問題] LIST<T>問題...
※ 引述《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
討論串 (同標題文章)
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章