I have an asp dropbox which I populate from database:
this is the aspx
<asp:DropDownList runat="server" ID="ddl_last" AppendDataBoundItems="true">
and this is the cs:
ddl_last.DataSource = eggsContext.Customers;
ddl_last.DataValueField = "last_name";
ddl_last.DataTextField = "last_name";
ddl_last.DataBind();
When I try to get ddl_last.SelectedValue from the c# code I get nothing. infact ddl_last.Items count is 0! When I don’t populate it from code, but write in the aspx
<asp:ListItem Text="example" />
everything works.
I can get the value from javascript by writing
document.getElementById(‘ddl_last’).value;
But I was wondering what did microsoft screw up this time that this is not working from the code behind?
After seeing your issue in comment, I think this may help you resolve it:
http://msdn.microsoft.com/en-us/library/system.web.ui.control.viewstatemode.aspx
Note also, with ViewState being disabled, you can still retrieve the posted value by