HTML 代码
<body>
<form id="form1" runat="server">
<div>
<div>
<select id="select1" runat="server">
C# 代码
protected void Button1_Click(object sender, EventArgs e)
{
String str = select1.Items[select1.SelectedIndex].Value;//获取下拉列表的value
Label1.Text = str; //通过Lable组件显示列表中的值
}
其中
String str = select1.Items[select1.SelectedIndex].Value;
中的select1
为HTML代码的select
组件的id
获取
Text
的方法与获取Value
的方法类似,只需要将String str = select1.Items[select1.SelectedIndex].Value;
中最后的.Value
改为.Text
即可