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

[Solved] optionlabel

1 Answer 102 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.
nachid
Top achievements
Rank 1
nachid asked on 20 Sep 2010, 03:59 PM
Is there a way to pass optionlabel to Html.Telerik().DropDownList()

I' am trying to migrate this portion of code

<%: Html.DropDownListFor(x => x, new SelectList(MyColorList, @"Value", @"Text"), "Please select a color")%>

to

<%=Html.Telerik().DropDownList()
                           .BindTo(new SelectList(MyColorList, @"Value", @"Text"))

%>

but I cannot figure out how to pass the optionLabel "Please select a color"

1 Answer, 1 is accepted

Sort by
0
Accepted
Adam Gritt
Top achievements
Rank 1
answered on 22 Sep 2010, 07:39 PM
Unfortunately, with the current implementation, this isn't possible directly (at least as far as I have seen).  If you specify the list of items to bind to, the Drop Down List will automatically select the first item and you cannot specify a SelectedIndex of -1 to say that you don't want anything selected.  However, if you need to do this you could do the following.  Change the DataBinding to Ajax or WebService and then add an OnLoad event handler that does the following code (assumes DropDownList is named TestDDL):

function onLoad() {
   if ($('#TestDDL').data('tDropDownList').text() == "&nbsp;") {
      $('#TestDDL').data('tDropDownList').text('Please select a color');
   }
}

I admit this isn't the best solution (best would be actual support for it), but it would get the job done.  
Tags
ComboBox
Asked by
nachid
Top achievements
Rank 1
Answers by
Adam Gritt
Top achievements
Rank 1
Share this question
or