RadComboBoxItem.Selected = true not working

3 posts, 1 answers
  1. Lynn
    Lynn avatar
    186 posts
    Member since:
    Sep 2006

    Posted 08 Jul 2011 Link to this post

    I have a combo box that I am attempting to populate in the page_load event and want the item in the combo box that corresponds to an incoming request string member value to be selected when done.  I have done this before and am not a "greenie", but I cannot get any item selected in the combo box.

    The definition of the combo box is in the code block immediately below:
    <telerik:RadComboBox ID="SearchCountry" TabIndex="5" style="z-index: 9000;" Width="200px" EnableEmbeddedSkins="true" Skin="Sitefinity" runat="server" Height="150px" OnClientSelectedIndexChanging="LoadSearchStateProv"></telerik:RadComboBox>

    The server-side code behind code is immediately below this line:
        Dim reader As SqlDataReader = cmd.ExecuteReader()
        Do While reader.Read()
            RCBI = New RadComboBoxItem()
            RCBI.Text = reader(sFieldToPopulate)
            RCBI.Value = reader("CodeList")
            If oValueToMatch = RCBI.Value Then
                RCBI.Selected = True
            End If
        reader = Nothing
    Catch ex As Exception
        Throw New ApplicationException("Error reading to populate country combo box from Select Statement=" & ComboSelectStmt & ". Code=" & ex.Message)
    End Try

    Can you please tell me what I am doing wrong?  The combo box is being populated correctly...but no item is selected when the page_load event completes and the page is visible.  Why?

    Thanks in advance!

  2. Answer
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Jul 2011 Link to this post

    Hello Lynn,

    I tried the same scenario and I cannot exactly reproduce the issue at my end. Please make sure that it is entering in to the loop.
    You can call the DataBind() method on the first page load and check whether there is any postback using "!Page.IsPostBack".

  3. Lynn
    Lynn avatar
    186 posts
    Member since:
    Sep 2006

    Posted 10 Jul 2011 Link to this post


    I have seen issues when "Selecting" a rad combobox item BEFORE adding it to the combobox list.  In fact, I made that change to the code by reversing the lines of code so that the ".selected = true" was the last line of related code and it worked just fine.
Back to Top