Generate DropDownList from code behind
<p>Hi I am generating a DropDownList in my code behind file </p>

<pre><code>    protected DropDownList CountryList() 
    {
        DropDownList ddl = new DropDownList();

        XDocument xmlDoc = XDocument.Load(Server.MapPath("Countries.xml"));
        var countries = from country in xmlDoc.Descendants("Country")
                        select new
                        {
                          Name = country.Element("name").Value,                              
                        };

        foreach (var c in countries)
        {
            ddl.Items.Add(c.Name);                
        }
        return ddl;
    }
</code></pre>

<p>I had dreams on then having &lt;%= CountryList() %> on my aspx page. But when I do this it prints the string - "System.Web.UI.WebControls.DropDownList".</p>

<p>Can I make this way of doing it work or do I have to setup a ContentPlaceHolder and then add the DropDownList to the content?</p>

<p>Cheers</p>
