ASP.net服务器控件,下拉框使用数组取值

来源:互联网 发布:启用访客网络什么意思 编辑:程序博客网 时间:2024/05/17 03:24
b<%@ Page Language="c#" %>
<script runat="server">

void Page_Load()
{
string msg = "You have selected: <br />";

if (list1.Items[0].Selected) {
msg = msg + list1.Items[0].Text + "<br />";
}
if (list1.Items[1].Selected) {
msg = msg + list1.Items[1].Text + "<br />";
}
if (list1.Items[2].Selected) {
msg = msg + list1.Items[2].Text + "<br />";
}
Message.Text = msg;
}

</script>
<html>
<head>
<title>Drop Down List Example</title>
</head>
<body>
<asp:Label id="Message" runat="server"></asp:Label>
<br />
<form runat="server">
Which city do you wish to look at hotels for?<br />
<br />
<asp:listbox id="list1" runat="server" selectionmode="multiple">
<asp:listitem>Madrid</asp:listitem>
<asp:listitem>Oslo</asp:listitem>
<asp:listitem>Lisbon</asp:listitem>
</asp:listbox>
<br />
<br />
<br />
<br />
<input type="submit" value="提交查询内容" />
</form>
</body>
</html>
原创粉丝点击