ComboBox SelectedIndex always -1 or 0

2 posts, 0 answers
  1. Tim
    Tim avatar
    20 posts
    Member since:
    Jan 2009

    Posted 26 Jun 2010 Link to this post

    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.

  2. Tim
    Tim avatar
    20 posts
    Member since:
    Jan 2009

    Posted 26 Jun 2010 Link to this post

    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.
Back to Top