Loop and add DropDown item in the Page instead of code-behind?
<p>I wonder if is possible to add DropDown item in the Page instead of Code-behind?</p>

<p>So say I have a DropDown box I want to show year 1900 ~ current year</p>

<pre><code>&lt;asp:DropDownList ID="ddlYear" runat="server" CssClass="text"&gt;
    &lt;% 
        int currentYear = DateTime.Now.Year;
        for (int i = 1900; i &lt; currentYear; i++)
        {
    %&gt;
        &lt;asp:ListItem&gt;&lt;%=i %&gt;&lt;/asp:ListItem&gt;
    &lt;%
        }
    %&gt;
&lt;/asp:DropDownList&gt;
</code></pre>

<p>Is it possible to do something like that?</p>

<p>Because when I try to do like above it gives me:</p>

<blockquote>
  <p>Warning   1   C:\SandBox\MyWebApplication1\MyWebApplication1\Default.aspx:
  ASP.NET runtime error: Code blocks are not supported in this
  context.  C:\SandBox\MyWebApplication1\MyWebApplication1\Default.aspx 35  1   MyWebApplication1</p>
</blockquote>

<p>Edit: I also tried:</p>

<pre><code>&lt;asp:DropDownList ID="DropDownList1" runat="server"&gt;

&lt;/asp:DropDownList&gt;

&lt;% 
    int currentYear = DateTime.Now.Year;

    if (currentYear &lt;= 1933)
    {
        currentYear = 2012;
    }
    for (int i = 1933; i &lt; currentYear; i++)
    {
        DropDownList1.Items.Add(new ListItem(i.ToString(), i.ToString()));
    }
%&gt;
</code></pre>

<p>But the DropDownList doesn't have items when display...</p>

<p>=====
Edit: As Splash-X suggested, now it rendered, but all items gone after postback....</p>

<pre><code>&lt;form id="form1" runat="server"&gt;
&lt;div&gt;
&lt;% 
    int currentYear = DateTime.Now.Year;
    if (!Page.IsPostBack)
    {
        if (currentYear &lt;= 1933)
        {
            currentYear = 2012;
        }
        DropDownList1.Items.Clear();
        for (int i = 1933; i &lt; currentYear; i++)
        {
            DropDownList1.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }
    }
%&gt;
&lt;asp:DropDownList ID="DropDownList1" runat="server"&gt;

&lt;/asp:DropDownList&gt;



    &lt;input id="Button1" type="button" value="button" onclick="MyFunction();"/&gt;
    &lt;div id="MyDiv"&gt;
    &lt;/div&gt;
    &lt;asp:Button ID="Button2" runat="server" Text="Button" /&gt;
&lt;/div&gt;
&lt;/form&gt;
</code></pre>
