asp.net(c#)web伺服器控制元件,多選框checkboxlist控制元件。
阿新 • • 發佈:2019-02-05
<%@ Page Language="c#" %>
<script runat="server">
void Page_Load()
{
string msg = "You have selected the following items:<br />";
if (check1.Items[0].Selected) {
msg = msg + check1.Items[0].Text + "<br />";
}
if (check1.Items[1].Selected) {
msg = msg + check1.Items[1].Text + "<br />";
}
if (check1.Items[2].Selected) {
msg = msg + check1.Items[2].Text + "<br />";
}
Message.Text = msg;
}
</script>
<html>
<head>
<title>Check Box List Example</title>
</head>
<body>
<asp:Label id="Message" runat="server"></asp:Label>
<br />
<br />
Which city do you wish to look at hotels for?
<br />
<br />
<form runat="server">
<asp:checkboxlist id="check1" runat="server">
<asp:listitem id="option1" runat="server" value="Madrid" />
<asp:listitem id="option2" runat="server" value="Oslo" />
<asp:listitem id="option3" runat="server" value="Lisbon" />
</asp:checkboxlist>
<br />
<br />
<input type="submit" value="提交查詢內容" />
</form>
</body>
</html>
<script runat="server">
void Page_Load()
{
string msg = "You have selected the following items:<br />";
if (check1.Items[0].Selected) {
msg = msg + check1.Items[0].Text + "<br />";
}
if (check1.Items[1].Selected) {
msg = msg + check1.Items[1].Text + "<br />";
}
if (check1.Items[2].Selected) {
msg = msg + check1.Items[2].Text + "<br />";
}
Message.Text = msg;
}
</script>
<html>
<head>
<title>Check Box List Example</title>
</head>
<body>
<asp:Label id="Message" runat="server"></asp:Label>
<br />
<br />
Which city do you wish to look at hotels for?
<br />
<br />
<form runat="server">
<asp:checkboxlist id="check1" runat="server">
<asp:listitem id="option1" runat="server" value="Madrid" />
<asp:listitem id="option2" runat="server" value="Oslo" />
<asp:listitem id="option3" runat="server" value="Lisbon" />
</asp:checkboxlist>
<br />
<br />
<input type="submit" value="提交查詢內容" />
</form>
</body>
</html>