如下列代码
获取value
HTML 代码
<body>
<form id="form1" runat="server">
<div>
<div>
<select id="select1" runat="server">
<option value ="video1" runat="server">视频1</option>
<option value ="video2" runat="server">视频2</option>
<option value="video3" runat="server">视频3</option>
</select>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="开始" />
</div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
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
获取
Text
的方法与获取Value
的方法类似,只需要将String str = select1.Items[select1.SelectedIndex].Value;
中最后的.Value
改为.Text
即可