[問題] 抓取DropDownList的值

看板C_Sharp (C#)作者 (特而)時間18年前 (2007/01/31 21:34), 編輯推噓2(203)
留言5則, 2人參與, 最新討論串1/1
想請問一下 我希望知道user選擇哪各option 然後把他存在字串select 顯示出來 但不知道哪裡寫錯了@@ <%@ Page Language="C#" %> <%@ Import NameSpace="System.Collections" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "" rel="nofollow">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> ArrayList al = new ArrayList(); public void Page_Load(Object obj, EventArgs e){ al.Add("1"); al.Add("2"); al.Add("3"); DropDownList1.DataSource = al; DropDownList1.DataBind(); } string select ="no" ; protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { select = DropDownList1.SelectedValue; } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Style="z-index: 100; left: 74px; position: absolute; top: 105px"> </asp:DropDownList> <asp:Label ID="Label1" runat="server" Style="z-index: 102; left: 79px; position: absolute; top: 154px" Text='<%#select %>'></asp:Label> </div> </form> </body> </html> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.130.182.221

02/01 23:06, , 1F
給它個出口吧!Label1.Text = select;
02/01 23:06, 1F

02/01 23:18, , 2F
還有postback問題 & string select = "no";擺放處問題
02/01 23:18, 2F

02/02 08:29, , 3F
請問一下 我string擺那邊是當作instance變數
02/02 08:29, 3F

02/02 08:30, , 4F
想不出哪裡錯 Orz
02/02 08:30, 4F

02/02 14:19, , 5F
ok~不好意思!那就前兩個問題解決了就ok囉~~
02/02 14:19, 5F
文章代碼(AID): #15m9i2GS (C_Sharp)
文章代碼(AID): #15m9i2GS (C_Sharp)