作者Turbine (特而)
看板C_Sharp
標題[問題] 抓取DropDownList的值
時間Wed Jan 31 21:34:57 2007
想請問一下
我希望知道user選擇哪各option
然後把他存在字串select
顯示出來
但不知道哪裡寫錯了@@
<%@ Page Language="C#" %>
<%@ Import NameSpace="System.Collections" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
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
推 coign:給它個出口吧!Label1.Text = select; 02/01 23:06
→ coign:還有postback問題 & string select = "no";擺放處問題 02/01 23:18
推 Turbine:請問一下 我string擺那邊是當作instance變數 02/02 08:29
→ Turbine:想不出哪裡錯 Orz 02/02 08:30
→ coign:ok~不好意思!那就前兩個問題解決了就ok囉~~ 02/02 14:19