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

Viewdata is not reflecting in Grid and dropdwonlist

1 Answer 276 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
europeitprocurement
Top achievements
Rank 1
europeitprocurement asked on 07 Nov 2012, 07:22 AM
Hello,

I'm new to the Kendo UI stuff, so please forgive me if this is an easy one; I've been trying to find some details that might tell me what I'm doing wrong, but nothing so far.

Based on radio selection I need to populate the dropdownlist values and grid. I am binding the values to dropdownlist and grid using Viewdata. Initially while loading the View there is no probelm grid and dropdownlist are loaded perfectely. but when i change the radio selection, it is not updating the grid and drodown list but data is reflected in view data.

usign this below function i am calling the controller

function Frequency(Mode) {
        var json = {
            'Frequency': Mode
        }
        $.ajax({
            url: '@Url.Action("Index", "Pricing")',
            type: 'Post',
            data: json,
            success: function (data) {
                $("#cboPricingDates").data("kendoDropDownList").dataSource.read();
                $("#PricingGrid").data("kendoGrid").dataSource.read();
                alert("OK");
            }
        });
    }

and this is my controller

 [HttpPost]
        public ActionResult Index(string Frequency)
        {
            LoadFundDates(Frequency); // this will update the viewdata of dropdown and viewdata of grid
           return View();
        }

and my dropdownlist in view

   @Html.Kendo().DropDownList().Name("cboPricingDates").BindTo((IEnumerable<SelectListItem>)ViewData["PricingDates"])

and my grid

 @{Html.Kendo().Grid((List<SAM.Enrol.Prg.Contract.VendorPricingGrid>)ViewData["PricingGrid"])
        .Name("PricingGrid")
        .DataSource(dataSource => dataSource
           
            .Ajax()
            .PageSize(25)
            .Model(q => q.Id(m => m.ProdId))
            .Model(q => q.Id(m => m.Ccy))
             .Model(q => q.Id(m => m.Cat))
            
                )
               
        .Columns(columns =>
        {
           // Columns goes here
        
        })
            


          .Resizable(resizing => resizing.Columns(true))
          .Scrollable(scrolling => scrolling.Enabled(true).Height(600))
          .Sortable(sorting => sorting.Enabled(true))
          .Groupable(grouping => grouping.Enabled(true))
          .Filterable(filtering => filtering.Enabled(true))
          .Reorderable(reorder => reorder.Columns(true))
          .Pageable(Pageable => Pageable.Enabled(true).PreviousNext(true).Input(true).PageSizes(true).Refresh(true))
          .RowAction(row => row.HtmlAttributes.Add("data-id", row.DataItem.ProdId))
          .RowAction(row => row.HtmlAttributes.Add("data-id", row.DataItem.Ccy))
          .RowAction(row => row.HtmlAttributes.Add("data-id", row.DataItem.Cat))
                      .Selectable(s => s.Mode(GridSelectionMode.Single).Enabled(true))
                      .Render();
                      }

Please help me to resolve this issue.


1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 12 Nov 2012, 06:35 AM
Hello,

 
After initial review of the code snippets, I noticed that the DropDownList widget does not use Ajax binding. In this case the dataSource.read() will not be able to re-load the data, because it does not which Action method to hit. I also noticed that the code tries to re-load data ( in this case the DataSource should use Ajax binding) in the complete callback of an Ajax request. If you need to bind the widgets to the returned data then you will need to use the data() method. I will also suggest you check these help topics:
http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/ajax-binding
http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/dropdownlist/overview

Here is a simple demo, which shows how to use read() method of the dataSource.

All the best,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
DropDownList
Asked by
europeitprocurement
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or