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

Problem when clear selected value

7 Answers 205 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Wahid
Top achievements
Rank 2
Wahid asked on 27 Aug 2011, 04:09 PM
Hi,
In the earlier versions you could clear selected value of Combobox by:
combobox.dataBind();
Then I call .reload(); to rebind the combobox.

In new release it do the work,
but keep in the box the previous value of the combobox.

So how to clear the combobox and rebind it in new release ?

7 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 29 Aug 2011, 08:23 AM
Hello Wahid,

I would suggest to call the following after reload()
combobox.value("");
combobox.text("");


Greetings,
Georgi Tunev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Wahid
Top achievements
Rank 2
answered on 26 Nov 2011, 01:06 AM
Hi Georgi,
This worked when the ComboBox field doesn't has a "Previous Value" as in create status.
But when i try to modify an old value by cascading this ComboBox the old value still stuck 
0
Georgi Tunev
Telerik team
answered on 30 Nov 2011, 10:23 AM
Hi Wahid,

Could you please provide a sample code so I can see your current implementation?


Kind regards,
Georgi Tunev
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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Wahid
Top achievements
Rank 2
answered on 30 Nov 2011, 05:28 PM
Here is an example :

I'm editing some product information which contains "RootCategoryId" and "SubCategoryId".
So when i change the RootCategoryId value the SubCategories ComboBox should be reload with the new values and it do indeed but it keeps the old value id as text value until i select the new value.
function onRootCategoryComboChange(e) {
    var combo = $("#SubCategoryId").data("tComboBox");
    if ($(combo).length > 0) {
        combo.value('');
        combo.text('');
        combo.dataBind();
        combo.reload();
    }
}
Here in the attachments two files to make the idea clear.

=======================================================================
Update:
Now this worked 
function onRootCategoryComboChange(e) {
    var combo = $("#SubCategoryId").data("tComboBox");
    if ($(combo).length > 0) {
        combo.value('');
        combo.text('');
        combo.selectedValue = ''; // Add this to clear the old value
        combo.dataBind();
        combo.reload();
    }
}

But i think this isn't the right way is it ??
0
Petur Subev
Telerik team
answered on 02 Dec 2011, 08:46 AM
Hello Wahid,

Basically you can subscribe a JavaScript function to the OnDataBound event of the sub ComboBox which 
can simply select the first item in the collection.
e.g.

@(Html.Telerik().ComboBox()
    .Name("SubComboBox")
    //...
    .ClientEvents(events => events.OnDataBound("SecondBounded"))
)

JavaScript function:
function SecondBounded() {
        var combo2 = $("#SubComboBox").data("tComboBox");
        combo2.select(0);
}


Kind regards,
Petur Subev
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 Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Yang
Top achievements
Rank 1
answered on 02 Apr 2013, 07:26 PM
Hi, 

I encountered the same problem where reload() does not clear the previously selected value.
My server can return an empty list as dropdown values, which means there are no valid values, thus the dropdown should be empty.
However, I am left with the value I previously selected, and there is no way to get rid of it.
Setting text() and value() doesn't work, text  is changed to blank but value is still the original  value I selected.
Any workaround is appreciated.

Thanks,
Yang
0
Jivan
Top achievements
Rank 1
answered on 30 Apr 2013, 05:08 PM
Hi,
This kind of problem can be fixed in databound event of telerik control where we can use following to reset the value.

telerikControle.selectedValue = '';
telerikControle.dataBind();
Tags
ComboBox
Asked by
Wahid
Top achievements
Rank 2
Answers by
Georgi Tunev
Telerik team
Wahid
Top achievements
Rank 2
Petur Subev
Telerik team
Yang
Top achievements
Rank 1
Jivan
Top achievements
Rank 1
Share this question
or