This is a migrated thread and some comments may be shown as answers.

ComboBox SelectedIndex always -1 or 0

1 Answer 159 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 26 Jun 2010, 09:14 PM
I've got two comboboxes with two objectdatasources:
<telerik:RadComboBox ID="RadComboBoxConnection" runat="server" Height="200px" Width="300px" 
        Filter="Contains" MarkFirstMatch="true" ChangeTextOnKeyBoardNavigation="false" AllowCustomText="false" 
        DataSourceID="ObjectDataSourceConnection" DataTextField="DatabaseFriendlyName" DataValueField="ImportConnectionId" AutoPostBack="true" EnableViewState="true"
</telerik:RadComboBox> 
 
<telerik:RadComboBox ID="RadComboBoxObject" runat="server" Height="200px" Width="300px" 
        Filter="Contains" MarkFirstMatch="true" ChangeTextOnKeyBoardNavigation="false" AllowCustomText="false" 
        DataSourceID="ObjectDataSourceObject" DataTextField="ObjectName" DataValueField="ImportObjectId" AutoPostBack="true" EnableViewState="true" OnSelectedIndexChanged="RadComboBoxObject_OnSelectedIndexChanged"
</telerik:RadComboBox> 
 
<asp:Literal ID="litMessage" runat="server" /> 
 
<asp:ObjectDataSource ID="ObjectDataSourceConnection" runat="server"  
    TypeName="Ams.Web.BackOffice.ImportConnectionAdapter"  
    DataObjectTypeName="Ams.Core.DomainObject.ImportConnection"  
    OldValuesParameterFormatString="original_{0}" 
    ConflictDetection="CompareAllValues" 
    SelectMethod="SelectImportConnection" /> 
 
<asp:ObjectDataSource ID="ObjectDataSourceObject" runat="server"  
    TypeName="Ams.Web.BackOffice.ImportObjectAdapter"  
    DataObjectTypeName="Ams.Core.DomainObject.ImportObject"  
    OldValuesParameterFormatString="original_{0}" 
    ConflictDetection="CompareAllValues" 
    SelectMethod="SelectImportObject"
        <SELECTPARAMETERS> 
            <asp:ControlParameter Name="aImportConnectionId" PropertyName="SelectedValue" ControlID="RadComboBoxConnection" /> 
        </SELECTPARAMETERS> 
    </asp:ObjectDataSource> 

The first combobox I have no problems with. I can selected any entry, and on postback it retains its values.
The second combobox however, when selecting a new item, it loses its value every time. Page_Init its SelectedIndex is -1. Page_Load, always 0!! Even when declaring OnSelectedIndexChanged, still 0. ALWAYS 0 or -1!
Any ideas? Thanks in advance.
PS. Also found something really quirky. I can select an entry, then if I deselect (lose the focus of the second combobox) it reverts to the SelectedIndex = 0.

1 Answer, 1 is accepted

Sort by
0
Tim
Top achievements
Rank 1
answered on 26 Jun 2010, 09:24 PM
The problem was between the keyboard and chair.
The DataValueField was null / 0 for all entries because the object I was binding to wasn't being initialized properly.
Tags
ComboBox
Asked by
Tim
Top achievements
Rank 1
Answers by
Tim
Top achievements
Rank 1
Share this question
or