ListBox Inside DataList Control Always Giving the Text of the First Item
<p>I have a ListBox inside DataList control. The Autopostback is set to true in the ListBox. </p>

<p>For some reason when I select an item from the ListBox control and I check in the ListBox_SelectionChanged event it is always the First item of the ListBox items. Why is that?</p>

<p>I just checked and the SelectedIndex is set to 0 even if I select the 5th or 6th item in the ListBox. </p>

<pre><code>           &gt;
      &lt;ItemTemplate&gt;
      &lt;div style="background-color:#FFCC99; border:2px solid black; padding:2px"&gt;
     &lt;div style="background-color:lightgreen; border:2px solid black; padding:2px"&gt;
      &lt;%# Eval("NounTypeName") %&gt;
      &lt;/div&gt;

       &lt;asp:ListBox ID="lbNounTypes" AutoPostBack="true" DataTextField="Key" DataValueField="NounTypeId" SelectionMode="Single"  
              DataSource='&lt;%# Eval("Attributes") %&gt;' runat="server" 
              onselectedindexchanged="lbNounTypes_SelectedIndexChanged"&gt;

       &lt;/asp:ListBox&gt;

 protected void lbNounTypes_SelectedIndexChanged(object sender, EventArgs e)
        {
            var lb = sender as ListBox;

            // lb.SelectedIndex is also 0
</code></pre>

<p>I think I may have found the problem. The ListBox DataValueField is same for a ListBox and the SelectedItem is returned based on the selection of the value. </p>
