Setting default value in kendodropdown from JSON data

6 posts, 0 answers
  1. Lloyd
    Lloyd avatar
    4 posts
    Member since:
    Feb 2012

    Posted 16 Sep 2015 Link to this post

    Please find the below code as i want to set default value of dropdown instead of optionlable from  JSON data which is returned
    from controller .
     
    Please find the below code

    public ActionResult GetOrders()
           {
               List<usp_IDQ_GetLicenseDistrictsVO> objresult1 = new List<usp_IDQ_GetLicenseDistrictsVO>();
               objresult1 = objConnection.usp_IDQ_GetLicenseDistricts(User.Identity.Name, true).ToList();
               return Json(objresult1, JsonRequestBehavior.AllowGet); ;
           }

    @(Html.Kendo().DropDownList()
                  .Name("DropDownList1")

                          //.Events(ev => ev.DataBound("SalesPersonID_DataBound"))
                          .OptionLabel("Select ...")
                  .HtmlAttributes(new { style = "width:300px" })
                  .OptionLabel("Select ...")
                  .DataTextField("District_Id")
                  .DataValueField("Location_ID")


                          .DataSource(source =>
               {
                   source.Read(read =>
                      {
                          read.Action("GetOrders", "IDTDashboard");
                      })
                      .ServerFiltering(true);
               })
               .AutoBind(false)


  2. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2566 posts

    Posted 18 Sep 2015 Link to this post

    Hello Lloyd,

     

    If you want to set a default value of the DropDownList you can use the value configuration option. It should be something like this:

     

    @(Html.Kendo().DropDownList()
              .Name("products")
              .DataTextField("ProductName")
              .DataValueField("ProductID")
              .Value("7")

    ....

    It is documented here as well:

     

    http://docs.telerik.com/kendo-ui/api/javascript/ui/dropdownlist#configuration-value

     

    Regards,

    Kiril Nikolov

    Telerik

    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 Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Lloyd
    Lloyd avatar
    4 posts
    Member since:
    Feb 2012

    Posted 18 Sep 2015 Link to this post

    How we will set the Json value in .Value feild? As Value("7") is harcoded feild.
  5. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2566 posts

    Posted 22 Sep 2015 Link to this post

    Hello Lloyd,

     

    You can use the JavaScript API to set the value of the widget, at any point after the initialization. Please check the following article and let me know if it helps:

     

    http://docs.telerik.com/kendo-ui/api/javascript/ui/dropdownlist#methods-value

     

    Regards,
    Kiril Nikolov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  6. Lloyd
    Lloyd avatar
    4 posts
    Member since:
    Feb 2012

    Posted 22 Sep 2015 in reply to Kiril Nikolov Link to this post

    even using this post refernce, we have to set harcode value using javascript.

    But i want to set default value of kendo dropdown  using my runtime JSON result.

  7. Kiril Nikolov
    Admin
    Kiril Nikolov avatar
    2566 posts

    Posted 22 Sep 2015 Link to this post

    Hello Lloyd,

     

    I think that I understand the issue more clearly now - you want to use the JSON response from the server to set the value of the widget, based on a property there. If this is the case, then you can use the dataBound event, and set the value of the widget there using the value() method suggested in the previous post. Please see the documentation about the dataBound event here:

     

    http://docs.telerik.com/kendo-ui/api/javascript/ui/dropdownlist#events-dataBound

     

    Regards,
    Kiril Nikolov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready