This is a migrated thread and some comments may be shown as answers.
ComboBox Displaying Value Of Property As Default Value
1 Answer 81 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
lmf232s
Top achievements
Rank 1
lmf232s asked on 11 Feb 2011, 04:47 PM
This may be by design but I don't recall having this issue with the previous version. Im currently using 2010.3.1318.

I have this code:
<%= Html.Telerik().ComboBoxFor(m => m.StateId)
      .AutoFill(true)
      .BindTo(new SelectList(ViewData["StateList"] as IEnumerable, "StateId", "StateShort"))
      .Filterable(filtering => filtering.FilterMode(AutoCompleteFilterMode.StartsWith))
      .HighlightFirstMatch(true)
%>

You'll notice that im creating the combobox for the StateId property of my viewModel and the list is nothing more than a list of {StateId = 1, StateShort = 'MO'}, etc.

The problem is that as soon as I click on the combobox, a 0 is displayed until I select a value. Yet if I don't select a value or tab out of the field the 0 stays. A 0 is not a valid value in my list for either text or value. This tells me that its grabbing the value of my property StateId, which in this case StateId is 0 as its an int that has not been set.

If I were reloading this page and I wanted the value of stateId to be selected I would assume I would set that value in the select list since there is a paramter to do so:
new SelectList(IEnumerable Items, string dataValueField, string dataTextField, object selectedValue)

So like I said earlier this may be by design. If so do you know of a work around, so that a 0 does not get displayed other than making my property a nullable field?

Thanks,
lmf232s

1 Answer, 1 is accepted

Sort by
0
lmf232s
Top achievements
Rank 1
answered on 11 Feb 2011, 05:38 PM

For the time being im calling the OnOpen event and checking to see if 0 is a vlaue for text or value and if so just setting them to 0. This works in the situation because 0 is not a valid id for my list

function OnOpen(e) {
    var comboBox = $("#" + e.currentTarget.id).data("tComboBox");
    if (comboBox.text() == 0 || comboBox.value == 0) {
        comboBox.text('');
        comboBox.value('');
    }
}
Tags
ComboBox
Asked by
lmf232s
Top achievements
Rank 1
Answers by
lmf232s
Top achievements
Rank 1
Share this question
or