function Button_Click(sender : Object, e : EventArgs) { Label1.Text = "You selected " + DropDownList1.SelectedItem.Text + "."; } </script> </head>
<body> <form runat="server"> <h3>DropDownList Data Bind Example</h3> Select an item from the list and click the submit button. <p> <asp:DropDownList id="DropDownList1" runat="server"/> <br><br> <asp:Button id="Button1" Text="Submit" OnClick="Button_Click" runat="server"/> <br><br> <asp:Label id="Label1" runat="server"/> </form> </body> </html>
i=1
function a()
{
o=document.form1.sel
o.options[o.length]=new Option("v"+i,"t"+i,true,true)
i++
}
function aa()
{
o=document.form1.sel
alert(o.options[o.selectedIndex].value + ":" + o.options[o.selectedIndex].text +":"+o.selectedIndex)
}
</script>
<form name=form1>
<select name=sel></select>
<input type=button onclick="a()" value=add>
<input type=button onclick="aa()" value="get">
</form>
<html>
<head>
<script language="JScript" runat="server">
function Page_Load(sender : Object, e : EventArgs)
{
if(!IsPostBack)
{
var myList : ArrayList = new ArrayList();
myList.Add ("Item 1");
myList.Add ("Item 2");
myList.Add ("Item 3");
myList.Add ("Item 4");
myList.Add ("Item 5");
DropDownList1.DataSource = myList;
DropDownList1.DataBind();
}
}
function Button_Click(sender : Object, e : EventArgs)
{
Label1.Text = "You selected " + DropDownList1.SelectedItem.Text + ".";
}
</script>
</head>
<body>
<form runat="server">
<h3>DropDownList Data Bind Example</h3>
Select an item from the list and click the submit button.
<p>
<asp:DropDownList id="DropDownList1"
runat="server"/>
<br><br>
<asp:Button id="Button1"
Text="Submit"
OnClick="Button_Click"
runat="server"/>
<br><br>
<asp:Label id="Label1"
runat="server"/>
</form>
</body>
</html>
完全可基于javascript or jscript vbscript 操作