- Home
- Forum
- ASP.NET MVC
- Hierarchical Grid
Hierarchical Grid
How should i bind my datasource for my grid i'm confused !
1. the first grid is bind with IEnumerable from Entity Framework
2. Why should i bind the Child grid with "Data Service" ??
In your example i see two different binding first grid IEnumerable and second grid with Data Service URL.
Can i bind both Grid with just Entity Framework without the need of Data Service ?
Please show me an example.
thanks for your help
1. the first grid is bind with IEnumerable from Entity Framework
2. Why should i bind the Child grid with "Data Service" ??
In your example i see two different binding first grid IEnumerable and second grid with Data Service URL.
Can i bind both Grid with just Entity Framework without the need of Data Service ?
Please show me an example.
thanks for your help
SIGN IN To post a reply.
4 Replies
TS
Thavasianand Sankaranarayanan
Syncfusion Team
December 28, 2016 11:44 AM UTC
Hi Martin,
Thanks for contacting Syncfusion support
Query : Can I bind the child grid without need of data service ?
Yes, we can bind the data source for child grid without need of data service. In below sample we bound the IEnumearble data for both parent and child grid.
Please refer the below code example
|
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.Columns(col =>
{
………………………..
})
.ChildGrid(child =>
{
child.Datasource((IEnumerable<object>)ViewBag.datasource2) // Binding data source for child Grid without using Data Service
.QueryString("EmployeeID")
.AllowPaging()
.Columns(col =>
{
…………………………………..
});
})
)
|
For your convenience we have prepared a sample and it will be downloaded from the below location
Sample: http://www.syncfusion.com/downloads/support/forum/128029/ze/SyncfusionMvcApplication9-2128232129
Regards,
Thavasianand S.
MA
Martin
December 28, 2016 09:57 PM UTC
Thank you so much for your help
And if i wanna add a third Grid
thank you.
It didn't worked
.ChildGrid(d =>
{
d.Datasource((IEnumerable<Order_Detail>)ViewBag.datasource3)
.QueryString("OrderID")
.AllowPaging()
{ col.Field("OrderID").HeaderText("OrderID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
col.Field("UnitPrice").HeaderText("UnitPrice").Width(100).Add();
col.Field("Quantity").HeaderText("Quantity").Width(120).Add();
col.Field("Discount").HeaderText("Discount").Width(100).Add();
});
})
)
)
thanks for your help.
And if i wanna add a third Grid
thank you.
It didn't worked
.ChildGrid(d =>
{
d.Datasource((IEnumerable<Order_Detail>)ViewBag.datasource3)
.QueryString("OrderID")
.AllowPaging()
{ col.Field("OrderID").HeaderText("OrderID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
col.Field("UnitPrice").HeaderText("UnitPrice").Width(100).Add();
col.Field("Quantity").HeaderText("Quantity").Width(120).Add();
col.Field("Discount").HeaderText("Discount").Width(100).Add();
});
})
)
)
thanks for your help.
MA
Martin
December 28, 2016 10:01 PM UTC
Sorry i forgot to include my controller code
var cust = new NORTHWNDEntities().Customers.ToList();
ViewBag.datasource = cust;
var ord = new NORTHWNDEntities().Orders.ToList();
ViewBag.datasource2 = ord;
var detail = new NORTHWNDEntities().Order_Details.ToList();
ViewBag.datasource3 = detail;
return View();
thanks agiain.
var cust = new NORTHWNDEntities().Customers.ToList();
ViewBag.datasource = cust;
var ord = new NORTHWNDEntities().Orders.ToList();
ViewBag.datasource2 = ord;
var detail = new NORTHWNDEntities().Order_Details.ToList();
ViewBag.datasource3 = detail;
return View();
thanks agiain.
PK
Prasanna Kumar Viswanathan
Syncfusion Team
January 2, 2017 06:43 AM UTC
Hi Martin,
We created a sample in Hierarchy with two child and please download the sample from the following link
Sample: http://www.syncfusion.com/downloads/support/forum/128029/ze/SyncfusionMvcApplication9-1755325950
Find the code example:
|
.Datasource((IEnumerable<object>)ViewBag.datasource)
------------------
.ChildGrid(child =>
{
child.Datasource((IEnumerable<object>)ViewBag.datasource2)
------------------------
})
.ChildGrid(d =>
{
d.Datasource((IEnumerable<object>)ViewBag.datasource2)
.QueryString("CustomerID")
.Columns(col =>
{
---------------------
});
});
})
) |
You have mentioned that you face issues while adding a third grid. So, please confirm the following details.
1. Share the screenshot of an issue.
2. Did you face any script error in console page? If yes, share the stackrace of an issue.
3. Ensure that you have mention the proper field in the QueryString property of ejGrid. The QueryString property is used to denote the primaryKey field of the parent grid which is to be mapped with the foreignKey field of the child grid. Based on the mapping, the child grid records are filtered from the table and is bound as datasource for the child grid.
4. Essential Studio Version details.
Refer to the Help document for the Hierarchy Grid.
Regards,
Prasanna Kumar N.S.V
SIGN IN To post a reply.
- 4 Replies
- 3 Participants
-
MA Martin
- Dec 27, 2016 08:40 PM UTC
- Jan 2, 2017 06:43 AM UTC