Many times I had came across a situation to display Master-Detail in a grid. Normally we accomplish this by binding the Detailgrid with on Item Data Bound of the Master Grid.
But if we have all Master Detail Data returning in a Collection,
for ex.
Order 1 , Customer1, OrderDate
Item1 , Item Name, Item Price, Qty, Total Price
Item2 , Item Name, Item Price, Qty, Total Price
Item3 , Item Name, Item Price, Qty, Total Price
Item4 , Item Name, Item Price, Qty, Total Price
Order 2 , Customer2, OrderDate
Item1 , Item Name, Item Price, Qty, Total Price
Item2 , Item Name, Item Price, Qty, Total Price
Item3 , Item Name, Item Price, Qty, Total Price
Item4 , Item Name, Item Price, Qty, Total Price
Order3 , Customer3, OrderDate
Item1 , Item Name, Item Price, Qty, Total Price
Item2 , Item Name, Item Price, Qty, Total Price
Item3 , Item Name, Item Price, Qty, Total Price
Item4 , Item Name, Item Price, Qty, Total Price
we can link
1) Create a User Control with a Property for Example Orders
Eg:
public object Orders
{
set
{
if (value is Order )
{
rptDetail.DataSource = ((Order)value).OrderItems;
rptDetail.DataBind();
}
}
}
And in the ASPX page when calling the grid, pass the Parameter Orders with 'Container.DataItem'
Eg:
EP:UCOrderItems ID="ucOrderItems" runat="server" Orders=''/>
This will bind the collection to the child grid
But if we have all Master Detail Data returning in a Collection,
for ex.
Order 1 , Customer1, OrderDate
Item1 , Item Name, Item Price, Qty, Total Price
Item2 , Item Name, Item Price, Qty, Total Price
Item3 , Item Name, Item Price, Qty, Total Price
Item4 , Item Name, Item Price, Qty, Total Price
Order 2 , Customer2, OrderDate
Item1 , Item Name, Item Price, Qty, Total Price
Item2 , Item Name, Item Price, Qty, Total Price
Item3 , Item Name, Item Price, Qty, Total Price
Item4 , Item Name, Item Price, Qty, Total Price
Order3 , Customer3, OrderDate
Item1 , Item Name, Item Price, Qty, Total Price
Item2 , Item Name, Item Price, Qty, Total Price
Item3 , Item Name, Item Price, Qty, Total Price
Item4 , Item Name, Item Price, Qty, Total Price
we can link
1) Create a User Control with a Property for Example Orders
Eg:
public object Orders
{
set
{
if (value is Order )
{
rptDetail.DataSource = ((Order)value).OrderItems;
rptDetail.DataBind();
}
}
}
And in the ASPX page when calling the grid, pass the Parameter Orders with 'Container.DataItem'
Eg:
EP:UCOrderItems ID="ucOrderItems" runat="server" Orders=''/>
This will bind the collection to the child grid
No comments:
Post a Comment