[問題]更新參數指向的物件?

看板C_Sharp (C#)作者 (tomex_ou)時間19年前 (2006/02/21 15:38), 編輯推噓3(301)
留言4則, 4人參與, 最新討論串1/4 (看更多)
我在webform拉入一個drowdownlist,想讓它在某個method內 重新指定為新物件: protected void Button1_Click(object sender, EventArgs e) { this.Add(this.CheckBoxList1); } protected void Add(CheckBoxList oldList) { CheckBoxList newList = new CheckBoxList(); newList.Items.Add(new ListItem("t1", "t1")); newList.Items.Add(new ListItem("t2", "t2")); oldList = newList; //注意這邊,原來的不會變 this.CheckBoxList1 = newList; //也不變 } 結果,當然原this.CheckBoxList1沒有增加項目。 但加上ref參數傳入,仍然沒有加入項目。 問題就是,到底如何能完全控制原this.CheckBoxList1的變數? 我要讓它跟著變化呀... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.78.132.15

02/21 16:00, , 1F
發現ref傳入是會改變item.cout變了,但web上顯示不會變!困擾
02/21 16:00, 1F

02/21 17:16, , 2F
好像直接this.CheckBoxList1.Items.Add("t1");就可以了
02/21 17:16, 2F

02/21 17:35, , 3F
疑問 你為什麽要換新的?? 有這必要嗎? 直接改內容呀?
02/21 17:35, 3F

02/21 17:50, , 4F
這...new一個新的Control 它的位置會在?
02/21 17:50, 4F
文章代碼(AID): #13-iDPLI (C_Sharp)
文章代碼(AID): #13-iDPLI (C_Sharp)