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

[Solved] rebind doesn't work for IEnumerable<DataRow> data source

3 Answers 94 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.
John
Top achievements
Rank 1
John asked on 08 Aug 2011, 05:15 PM
Hi,

I noticed a strange issue when trying to rebind grid.

This code works fine(LineID is passed to Details grid as parameter to do data binding):
In View:
@(Html.Telerik().Grid((IEnumerable<Detail>)ViewData["DetailsData"])
        .Name("Details")
        .DataKeys(keys => { keys.Add("LineID"); })
        .Columns(columns=>
        {
            columns.Bound(typeof(string), "LineID").Visible(false);
            columns.Bound(typeof(string), "Name").Width(400).Title("Name");
            columns.Bound(typeof(string), "TotalNumber").Width(300).Title("TotalNumber");
        })
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_DetailsAjax", "Test", new { LineID = "<#= LineID #>" }))
        .ClientEvents(clientEvents => clientEvents.OnDataBinding("details_onDataBinding"))
        .Pageable()
        .Sortable()
)
 
In Controller:
[GridAction]
public ActionResult _DetailsAjax(int LineID)
{
     return View(new GridModel<Detail> {
         Data = GetDetails(LineID)
     });
}
 
public IList<Detail> GetDetails(int LineID)
{
     List<Detail> details = new List<Detail>();
       // Get detail data
     return details;
}

But When I modified it to use Datatable and Datarow instead of Detail class what is defined by myself, the rebind doesn't works at all:
In View:
@(Html.Telerik().Grid((IEnumerable<System.Data.DataRow>)ViewData["DetailsData"])
        .Name("Details")
        .DataKeys(keys => { keys.Add("LineID"); })
        .Columns(columns=>
        {
            columns.Bound(typeof(string), "LineID").Visible(false);
            columns.Bound(typeof(string), "Name").Width(400).Title("Name");
            columns.Bound(typeof(string), "TotalNumber").Width(300).Title("TotalNumber");
        })
        .DataBinding(dataBinding => dataBinding.Ajax().Select("_DetailsAjax", "Test", new { LineID = "<#= LineID #>" }))
        .ClientEvents(clientEvents => clientEvents.OnDataBinding("details_onDataBinding"))
        .Pageable()
        .Sortable()
)
  
In Controller:
[GridAction]
public ActionResult _DetailsAjax(int LineID)
{
     return View(new GridModel<System.Data.DataRow> {
         Data = GetDetails(LineID)
     });
}
  
public IEnumerable<System.Data.DataRow> GetDetails(int LineID)
{
      DataTable details = new DataTable();
      // Get detail data
      return details.AsEnumerable();;
}


Can anyone help me to figure out what's wrong with it if I use IEumerable<DataRow> instead of IEnumberable<Detail>?
Thanks!!

3 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 09 Aug 2011, 08:08 AM
Does anyone know why it doesn't work?
Need help! :(
0
John
Top achievements
Rank 1
answered on 09 Aug 2011, 03:02 PM
up.
can anyone help to figure out what's the reason?
Thanks!
0
John
Top achievements
Rank 1
answered on 10 Aug 2011, 04:43 PM
up
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Share this question
or