Hello there.
I have problem using this code which populates a dropdownlist with the name of the month compared to the current month. From this month on, the dropdownlist is empty. What am I doing wrong?
int currentMonth = DateTime.Today.Month;
for (int i = ddl.Items.Count; i >= 0; i--)
{
if (i > currentMonth)
{
ddl.Items.RemoveAt(i - 1);
}
}
<asp:DropDownList ID="ddl"
runat="server"
BackColor="Yellow"
CssClass="pure-u-23-24">
<asp:ListItem Text="[== ==]" Value=""></asp:ListItem>
<asp:ListItem Text="Jan" Value="1"></asp:ListItem>
<asp:ListItem Text="Feb" Value="2"></asp:ListItem>
<asp:ListItem Text="Mar" Value="3"></asp:ListItem>
<asp:ListItem Text="Apr" Value="4"></asp:ListItem>
<asp:ListItem Text="May" Value="5"></asp:ListItem>
<asp:ListItem Text="Jun" Value="6"></asp:ListItem>
<asp:ListItem Text="Jul" Value="7"></asp:ListItem>
<asp:ListItem Text="Aug" Value="8"></asp:ListItem>
<asp:ListItem Text="Sep" Value="9"></asp:ListItem>
<asp:ListItem Text="Oct Value="10"></asp:ListItem>
<asp:ListItem Text="Nov" Value="11"></asp:ListItem>
<asp:ListItem Text="Dec" Value="12"></asp:ListItem>
</asp:DropDownList>