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

[Solved] OnRowDataBound not receiving parameter

0 Answers 44 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Shira
Top achievements
Rank 1
Shira asked on 18 Mar 2012, 02:31 AM
QUESTION WITHDRAWN.  SOLUTION BELOW:

I was having an issue with grid not passing dataitem parameter to OnRowDataBound method.  Not sure what was wrong with my original grid, but I have a very simple grid now that works fine for this:

View:
@using MyCompany.Model;
@{
    ViewBag.Title = "Location List";
}
@model PagedResponse<LocationForListView>
<script type="text/javascript">
    function onRowDataBound(e) {
        alert('row databound');
        var dataItem = e.dataItem;
    }
  
</script>
@(Html.Telerik().Grid<LocationForListView>()
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.Id);
        columns.Bound(p => p.LocationName).Width(130).Format("{0:c}");
    })
    .DataBinding(dataBinding => dataBinding.Ajax().Select("TelerikDemoPaging", "ApplicationProcess", new { accountId = ViewBag.AccountId }))
    .ClientEvents(events => events
            .OnRowDataBound("onRowDataBound")
            )
)

Controller:
[OutputCache(Duration = 0, VaryByParam = "None")]
public ActionResult TelerikDemo()
{
    ViewBag.ApplicationId = 1;
    var model = new PagedResponse<LocationForListView>();
    model.PageSize = 10;
    return View("TelerikDemo", model);
}
[GridAction(EnableCustomBinding = true)]
public ActionResult TelerikDemoPaging(GridCommand command)
{
    var model = new List<LocationForListView>();
    model.Add(new LocationForListView
    {
        Id = 1,
        LocationName = "MyLocation"
    });
    model.Add(new LocationForListView
    {
        Id = 2,
        LocationName = "MyLocation"
    });
    return View(new GridModel { Data = model, Total = 1 });
}
Tags
Grid
Asked by
Shira
Top achievements
Rank 1
Share this question
or