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

[Solved] Combobox inserts "0" when first items value is > 0

3 Answers 126 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.
Thomas
Top achievements
Rank 1
Thomas asked on 22 May 2011, 09:33 PM

Environment:

  • ASP.NET MVC 3
  • VB.NET
  • Razor ViewEngin
  • Telerik MVC 2011-Q1.

 

I have a strange problem with the Combobox control.

If I run the following code in a View then "0" will be inserted as the first item when I press the "down" arrow,

 

@(Html.Telerik().ComboBox() _
        .Name("iComputerId") _
        .AutoFill(True) _
        .OpenOnFocus(False) _
        .HighlightFirstMatch(True) _
        .Items(Function(item) item.Add().Text("Item1").Value("1")) _
        .SelectedIndex(0))

But, if I run this code (note .value("0")), then the combobox will work as expected (i.e. only display "Item1").

 

 

@(Html.Telerik().ComboBox() _
        .Name("iComputerId") _
        .AutoFill(True) _
        .OpenOnFocus(False) _
        .HighlightFirstMatch(True) _
        .Items(Function(item) item.Add().Text("Item1").Value("0")) _
        .SelectedIndex(0))

The same problem occur if I bind the Combobox to a database and this causes a serious problem since it is very likely that there will not be any item that has "0" as its primary key i the queries I make.

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 23 May 2011, 09:16 AM
Hello Thomas,

 
The aforementioned issue could be caused when ComboBox UI component is named as a ViewData Key/Value pair. In other words if ViewData.iComputerId is 0, then selectedValue of the combobox will be also 0. The value will be applied on the client-side.

We will address this issue in the next official release of Telerik extensions for ASP.NET MVC.

Currently I can suggest you as a workaround rename the combobox or set the correct value using Value() method. Here us a code snippet showing how to implement second approach:

@(Html.Telerik().ComboBox()
        .Name("iComputerId")
        .AutoFill(true)
        .OpenOnFocus(false)
        .HighlightFirstMatch(true)
        .Items(item => item.Add().Text("Item1").Value("1"))
        .Value("1"))

As a token of gratitude for your involvement I have updated your Telerik points.


Regards,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Nebras
Top achievements
Rank 1
answered on 19 Dec 2011, 09:29 AM
I have the same issue but i have no ViewData with the same name of the grid , any suggestions?
0
Nebras
Top achievements
Rank 1
answered on 07 Feb 2012, 10:21 AM
??
Tags
ComboBox
Asked by
Thomas
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Nebras
Top achievements
Rank 1
Share this question
or