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

RadComboBoxItem.Selected = true not working

2 Answers 297 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Lynn
Top achievements
Rank 2
Lynn asked on 08 Jul 2011, 05:31 AM
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:
Try
    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
        RadComboBox1.Items.Add(RCBI)
    Loop
    reader.Close()
    reader = Nothing
Catch ex As Exception
    Throw New ApplicationException("Error reading to populate country combo box from Select Statement=" & ComboSelectStmt & ". Code=" & ex.Message)
Finally
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!

Lynn

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 08 Jul 2011, 07:43 AM
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".

Thanks,
Princy.
0
Lynn
Top achievements
Rank 2
answered on 11 Jul 2011, 01:30 AM
Princy,

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.
Tags
ComboBox
Asked by
Lynn
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Lynn
Top achievements
Rank 2
Share this question
or