For loop controlled by dropdownlist (C#)
<script language="C#" runat="server">
void Page_Load()
{
int number, counter;
if (Page.IsPostBack) {
number = Convert.ToInt32(NumberAttendees.SelectedItem.Value);
Message1.Text = "";
for (counter = 0; counter < number; counter ++)
{
Message1.Text += "Attendee Name ___________________<br /><br />" +
"Attendee Age _________________<br /><br /><hr /><br />";
}
}
}
</script>
<html>
<head>
<title>Loop Example</title>
</head>
<body>
<form runat="server">
Enter the number of attendees(max 6):
<br>
<br>
<asp:dropdownlist id="NumberAttendees" runat="server">
<asp:listitem>1</asp:listitem>
<asp:listitem>2</asp:listitem>
<asp:listitem>3</asp:listitem>
<asp:listitem>4</asp:listitem>
<asp:listitem>5</asp:listitem>
<asp:listitem>6</asp:listitem>
</asp:dropdownlist>
<br>
<br>
<input type="submit">
<br>
<br>
<asp:label id="Message1" runat="server"/>
</form>
</body>
</html>
Related examples in the same category