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

[Solved] DropDownList Item Value Not Returning

2 Answers 65 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.
Brian Lehmann
Top achievements
Rank 2
Brian Lehmann asked on 22 Jun 2011, 07:38 PM
I'm having a problem retrieving the value of a DropDowList item. I'm subscribing to the onChange event of the control and in that event I'm doing a simple test to retrieve the value, however each time I get back the text.

My DropDowList is defined as follows:
<%
                        List<ListItem> list_items = new List<ListItem>
                                                        {
                                                            new ListItem {Text = "List", Value = "1"},
                                                            new ListItem {Text = "Map", Value = "2"},
                                                            new ListItem {Text = "Chart", Value = "3"}
                                                        };
                        Html.Telerik().DropDownList()
                            .Name("DropdownBox")
                            .BindTo(new SelectList(list_items))
                            .SelectedIndex(0)
                            .ClientEvents(events => events.OnChange("listChange"))
                            .Render();
                    %>

And my event handler has code that looks like this:
var combobox = $(this).data('tDropDownList');
console.log(combobox.text());
console.log(combobox.value());

When I check the console in Firebug, both lines display the Text value that was selected with the value nowhere to be found.

Is there something I'm missing here? I'm on version 2011.1.414. . .

Thanks in advance for the help!
brian

2 Answers, 1 is accepted

Sort by
0
Brian Lehmann
Top achievements
Rank 2
answered on 22 Jun 2011, 07:45 PM
Another quick update - it seems I have to use the Text value to change to change the value as well.

For instance, this has no effect:
var combobox = $('#DropDownList').data('tDropDownList');
combobox.value('1');

But this works:
var combobox = $('#DropDownList').data('tDropDownList');
combobox.value('Chart');
0
Georgi Krustev
Telerik team
answered on 23 Jun 2011, 09:20 AM
Hello Brian Lehmann,

 
When creating SelectList from custom object, you will need to define dataTextField and dataValueField.
Check this article for more information.
Also you can check this online demo, which shows how to use it.

All the best,
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
Tags
ComboBox
Asked by
Brian Lehmann
Top achievements
Rank 2
Answers by
Brian Lehmann
Top achievements
Rank 2
Georgi Krustev
Telerik team
Share this question
or