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

ComboBox SelectedValue Not Working

23 Answers 1476 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Praveen
Top achievements
Rank 1
Praveen asked on 18 Sep 2009, 04:20 PM
The SelectedValue is working in the WebPage but if you create a usercontrol and put the RadComboBox and try to set the

SelectedValue it is not working. Any idea why it is behaving like this?

23 Answers, 1 is accepted

Sort by
0
Adam
Top achievements
Rank 1
answered on 21 Sep 2009, 05:58 AM
Hi,

We are experienceing this as well.

The Selected value is being set but is not displaying in the rendered combobox.

This is quite a serious issue for us so could you advise of the fix or work around ASAP.

Thanks.
0
Helen
Telerik team
answered on 23 Sep 2009, 10:31 AM
Hi,

What is the exact RadComboBox setup you are using?
We tested the behavior locally, but couldn't reproduce the issue. Please find attached our test files.
Could you modify them so we can see the problem you experience?

Kind regards,
Helen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Absolute Data Group
Top achievements
Rank 1
answered on 22 Oct 2009, 04:14 AM
I am getting a similar issue. In my case the RadComboBox is loaded from a user control and the very first time it is loaded into the page, it works correctly (Sets the selected value). However, on subsequent postbacks, the combo box loads with the value that it initially loaded with, even though the a new value has been selected. (I have tested this in the debugger).

The code that I am using in the usercontrol looks something like this (you can see I have tried multiple ways to set this value correctly):

        Label1.Text = _PD.DisplayName 
        Dim tText As New RadComboBox() 
        tText.ID = _PD.Name 
 
        tText.Width = New Unit("200px"
        tText.LoadContentFile(_ConfigFile) 
        tText.EnableViewState = False 
        ''tText.SelectedIndex = tText.Items.FindItemIndexByValue(_PD.GetValue(_Node)) 
        tText.SelectedValue = _PD.GetValue(_Node) 
        ''tText.Items.FindItemByValue(_PD.GetValue(_Node)).Selected = True 
        PlaceHolder1.Controls.Add(tText) 

However, oddly enough, if I do something that removes the user control after a post back, then trigger it to load again... the correct value will appear! It is only when the control being posted back is re-created that this behavior is present... which boggles my mind since I have implicitly turned off the viewstate.

Not to sound sour her, but frankly I have been a little disapointed with using Telerik controls in usercontrols. This isn't the first little annoying bug that I have run into and I suspect the issue is client side scripting (usual culprit).




0
Absolute Data Group
Top achievements
Rank 1
answered on 22 Oct 2009, 05:04 AM
I changed my code to use the normal ASP.NET dropdown control and it works flawlessly :(

        Dim _DD As New DropDownList() 
        _DD.Width = New Unit("200px"
        _DD.ID = _PD.Name 
        _DD.EnableViewState = False
        Dim _Doc As XmlDocument = New XmlDocument() 
        _Doc.Load(Server.MapPath(_ConfigFile)) 
 
        Dim _ItemList As XmlNodeList = _Doc.SelectNodes("//Item"
 
        For Each _Item As XmlElement In _ItemList 
            Dim _LI As New ListItem(_Item.GetAttribute("Text"), _Item.GetAttribute("Value")) 
            _DD.Items.Add(_LI) 
        Next 
 
        _DD.SelectedValue = _PD.GetValue(_Node) 
 
        PlaceHolder1.Controls.Add(_DD) 

Which leads me to ask... what the heck is going on with the RadComboBox? I checked every single value and as far as I can tell everything appears to be set correctly, but when the text box renders client side, the selected value always resets to the value selected the first time the control loads.

0
Veselin Vasilev
Telerik team
answered on 26 Oct 2009, 10:30 AM
Hi John Martinez,

I believe the best way to answer your question is to reproduce the problem locally first. Please open a support ticket and attach a running project there.
Thanks

All the best,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ryan
Top achievements
Rank 1
answered on 16 Jun 2011, 05:06 PM
Hello Telerik Team,

I am having this same (almost exact) problem, was there ever a solution to this issue?? The thread just died with no resolution...

Thank you.
0
Dimitar Terziev
Telerik team
answered on 20 Jun 2011, 02:18 PM
Hello Ryan,

Please specify what exactly is the problem you are experiencing and provide information on the particular implementation so we could help you out. 

Greetings,
Dimitar Terziev
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Dave
Top achievements
Rank 1
answered on 12 Jul 2011, 05:13 AM
I am having this issue as well when the combobox is inside a user control. See my recent post about ComboBox.Text not showing the selected item text. Please fix this...
0
Dave
Top achievements
Rank 1
answered on 12 Jul 2011, 05:16 AM
Is there a known problem in this area or not? Thanks...
0
Dimitar Terziev
Telerik team
answered on 14 Jul 2011, 03:26 PM
Hello Dave,

I've already responded to your problem in this forum thread here. In case this is a different issue, please accept my apologies and provide me with more information about the implementation  of your scenario.

All the best,
Dimitar Terziev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Erik
Top achievements
Rank 2
answered on 18 Apr 2012, 02:33 PM
Hello all,

I got exactly the same behaviour:
http://www.telerik.com/community/forums/aspnet-ajax/combobox/combobox-selectedvalue-not-working.aspx#977218 

The combo is part of a few controls being loaded dynamically, a RadNumericTextBox, a RadDatePicker and a RadComboBox
All works fine. Data is loaded like ecpercted. Then, I change the sel item of the combo. On postback controls are loaded (init) with old values(thats ok, from the init event, before viewstate is placed), then the selectedIndexChanged is triggered (fine), the controls are rebuilded, and I can see the right values being passed to the combo (and the others) but when done, the selectedvalue is trhe prev value and not the value I just selected while the other changes are still correct...

This all happens in a single page app whith dynamically loaded usercontrols.
' Text input for figure source
Dim rcb As New Telerik.Web.UI.RadComboBox
With rcb
    .ID = "Input_FOID" & FOIdx & "_Source"
    .Items.Clear()
    .Items.Add(New Telerik.Web.UI.RadComboBoxItem("(Onbekend)", "(Onbekend)"))
    .Items.Add(New Telerik.Web.UI.RadComboBoxItem("Interne cijfers", "Interne cijfers"))
    .Items.Add(New Telerik.Web.UI.RadComboBoxItem("Concept cijfers accountant", "Concept cijfers accountant"))
    .Items.Add(New Telerik.Web.UI.RadComboBoxItem("Gecons. concept cijfers accnt", "Gecons. concept cijfers accnt"))
    .Items.Add(New Telerik.Web.UI.RadComboBoxItem("Officiële vennootsch. cijfers", "Officiële vennootsch. cijfers"))
    .Items.Add(New Telerik.Web.UI.RadComboBoxItem("Officiële gecons. cijfers", "Officiële gecons. cijfers"))
    .Items.Add(New Telerik.Web.UI.RadComboBoxItem("KvK/D&B cijfers", "KvK/D&B cijfers"))
    .DropDownWidth = New Unit("220px")
    .MarkFirstMatch = True
    .Enabled = (ent_FinancialOverview.Locked Is Nothing)
    .Width = New Unit("147px")
    .ToolTip = "Source of figures"
End With
rcb.SelectedValue = ent_FinancialOverview.Source
'or...
rcb.SelectedIndex = rcb.FindItemByText(ent_FinancialOverview.Source).Index
Td.Controls.Add(rcb)
There is no databinding.

Erik
0
Dimitar Terziev
Telerik team
answered on 23 Apr 2012, 08:33 AM
Hi Erik,

I've made a sample page using the provided code snippet and everything is working properly on my side. The SelectedValue of the RadComboBox is the right one once a post-back occurs. I'm sending the sample page which I've been testing with so you could inspect it locally. The version of the controls which is
2012.1.411.

Greetings,
Dimitar Terziev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
King Du
Top achievements
Rank 2
answered on 01 Oct 2012, 05:10 PM
I am seeing the same exact problem, was anyone able to workaround it?

-pg
0
Erik
Top achievements
Rank 2
answered on 02 Oct 2012, 10:44 AM
Hello PG,

I did not check any futher, I just replaced the combo with a MS Combobox because I did not have the time to investigate. (I still do not... )

Regards,

Erik
0
King Du
Top achievements
Rank 2
answered on 02 Oct 2012, 12:03 PM
Thanks for the response Erik, I ended up creating a very simple project which reproduces my problem and opened a support ticket. Doesn't look like I can attach the project to this thread so you can see it but I will let you know once I hear back from Telerik.

-pg
0
Erik
Top achievements
Rank 2
answered on 02 Oct 2012, 12:18 PM
That's great PG! And please keep me informed!

Erik
0
David
Top achievements
Rank 1
answered on 31 Jan 2013, 09:50 AM
I´m experience the same problem! I´m on a tight deadline and this is a real bump in the road, feels this is a standard feature that should not be a problem... I´m not using a usercontrol just a standard .aspx. It´s running in a sharepoint project thou.

ASPX:
 
<telerik:RadComboBox ID="rcbX" runat="server" DataValueField="Id" AllowCustomText="false"
    EnableLoadOnDemand="true" OnClientSelectedIndexChanged="ClearYComboBox"
    DataTextField="Namn" EmptyMessage="Choose X">
    <WebServiceSettings Method="GetAllX" Path="/X.asmx" />                   
</telerik:RadComboBox>
 
Codebehind:

Page_Load:
        private void LoadAllX()
        {
            try
            {
                var svc = new XService();
                _X = svc.GetAllX();
 
                rcbX.DataSource = _X;
                rcbX.DataBind();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
 
        private void BindObject()
        {
             rcbX.SelectedValue = _object.X.Id.ToString();
        }
0
Erik
Top achievements
Rank 2
answered on 31 Jan 2013, 09:55 AM
Hello David and Telerik,


I'm also curious about a solution.

PG created a sample problem project and created a support ticket. 

How did that work out?


Regards,

Erik
0
Dimitar Terziev
Telerik team
answered on 05 Feb 2013, 08:47 AM
Hi Erik,

There had been two solution provided in the support ticket opened by PG. The first one was to create the RadComboBox in the page init event instead of the page load. The second one was to change the SelectedValue after the control is added to the controls collection of the page. The same page used in the support ticket is attached for reference.

All the best,
Dimitar Terziev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Erik
Top achievements
Rank 2
answered on 15 Feb 2013, 05:43 PM
Thanks Dimitar.

Had the problem today again. It does seem logical to load items on init, because of the viewstate: I now had a combobox in a radgrid edit form on a usercontrol. The usercontrol is dynamically loaded. When the combobox loads elements on load, I can imagine the selectedValue property to be reset... Doing it in the init of the combobox loads the elements before the viewstate is put back.

Erik
0
Wes
Top achievements
Rank 1
answered on 26 Jul 2013, 06:26 PM
I believe that I've found a solution to this exact problem, at least in my situation. 

Before you set the .SelectedValue call the .ClearSelection() method.  In my case, where the combo box is tied to an object data source on the page, this caused the selected value to actually update on EVERY attempt.

Assume you have a combo box named called radCombo1

radCombo1.ClearSelection()
radCombo1.SelectedValue = "TheOneIWant"
0
Jennifer
Top achievements
Rank 1
answered on 02 Dec 2013, 10:46 PM
.
0
Rob
Top achievements
Rank 1
Veteran
Iron
answered on 21 Nov 2017, 03:22 PM
Perfect! That worked for me. 
Tags
ComboBox
Asked by
Praveen
Top achievements
Rank 1
Answers by
Adam
Top achievements
Rank 1
Helen
Telerik team
Absolute Data Group
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Ryan
Top achievements
Rank 1
Dimitar Terziev
Telerik team
Dave
Top achievements
Rank 1
Erik
Top achievements
Rank 2
King Du
Top achievements
Rank 2
David
Top achievements
Rank 1
Wes
Top achievements
Rank 1
Jennifer
Top achievements
Rank 1
Rob
Top achievements
Rank 1
Veteran
Iron
Share this question
or