<%@ Page Language="c#" Explicit="true" Strict="true" %>
<script language="c#" runat="Server">
public void Verify(object sender, EventArgs e)
{
if (CountryListBox.SelectedIndex != -1)
{
OutputLabel.Text = "You selected: ";
if (CountryListBox.SelectionMode == ListSelectionMode.Single)
OutputLabel.Text += "<b>" + CountryListBox.SelectedItem.Text + "</b>";
else
{
for (int j=0;j<CountryListBox.Items.Count;j++)
{
if (CountryListBox.Items[j].Selected)
OutputLabel.Text += "<b>" + CountryListBox.Items[j].Text + "</b>, ";
}
}
}
else
OutputLabel.Text = "You didn't selected any country!";
}
</script>
<html>
<head>
<title></title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:ListBox ID="CountryListBox" Runat="server" SelectionMode="Multiple">
<asp:ListItem Value="1">United States</asp:ListItem>
<asp:ListItem Value="2">United Kingdom</asp:ListItem>
<asp:ListItem Value="3">China</asp:ListItem>
<asp:ListItem Value="4">India</asp:ListItem>
</asp:ListBox><br>
<asp:Button ID="SubmitButton" Runat="server" Text="Submit" OnClick="Verify"></asp:Button>
<asp:Label ID="OutputLabel" Runat="server"></asp:Label>
</form>
</body>
</html>
|