Can't set value in DropDownList/ComboBox

2 posts, 1 answers
  1. Benjamin
    Benjamin avatar
    12 posts
    Member since:
    Apr 2011

    Posted 18 Apr 2013 Link to this post

     Hi,

    I'm upgrading the kendo to the new one (Spring) and after that, I can't set the selected value for DropDown and Combobox. 
    It was ok before when i'm using the old version.
    And its happen not only in chrome, but in all browser.

    I'm using Visual Studio 2012 (MVC 4), and the new Jquery (1.9.1) and JQuery.Validate.Min.js

    following is the code snippet:
    @(Html.Kendo().DropDownList()
    .Name("color")
    .DataTextField("Text")
    .DataValueField("Value")
    .Value("2")
    .BindTo(new List<SelectListItem>() {
    new SelectListItem() {
    Text = "Black",
    Value = "1"
    },
    new SelectListItem() {
    Text = "Orange",
    Value = "2"
    },
    new SelectListItem() {
    Text = "Grey",
    Value = "3"
    }
    })
    )

    It always selects  1 instead of 2?!

    Any ideas why?

    Thanks :)
  2. Answer
    Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2156 posts

    Posted 19 Apr 2013 Link to this post

    Hello Benjamin,


    To set the value in the current scenario, you should set it after binding the DropDown to the List of items.
    E.g.
    @(Html.Kendo().DropDownList()
      ...
      .BindTo(new List<SelectListItem>() {
          new SelectListItem() {
              Text = "Black",
              Value = "1"
          },
          new SelectListItem() {
              Text = "Orange",
              Value = "2"
          },
          new SelectListItem() {
              Text = "Grey",
              Value = "3"
          }
      })
      .Value("3")

     

    Greetings,
    Dimiter Madjarov
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top