No matter what I try, I can't get the SelectedValue from my listbox on postback. I have triple-checked and even verified by stepping through code that I'm not rebinding my listbox to the datasource on postback (button click).
listbox declaration:
<asp:ListBox ID="listAvailableAMCs" Rows="8" Width="300px" DataValueField="ID" DataTextField="Company" runat="server"></asp:ListBox>
Listbox data population works fine.
A button click calls this:
protected void LinkAMC(object sender, EventArgs e)
{
if(listAvailableAMCs.SelectedValue != string.Empty)
Utilities.LinkAMC(int.Parse(listAvailableAMCs.SelectedValue));
LoadGridData();
}
SelectedValue is always blank. SelectedText is blank and SelectedIndex is -1.
A view source reveals this html:
<select size="8" name="ctl00$MasterMain$listAvailableAMCs" id="MasterMain_listAvailableAMCs" style="width:300px;">
<option value="19">Como AMC</option>
<option value="21">Sinatra AMC</option>
<option value="20">Martin AMC</option>
</select>
Those option values and text values are exactly right.
What am I missing?
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.