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

Hierachical RadGrid with simple ListDataSource

2 Answers 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prasanth100
Top achievements
Rank 1
Prasanth100 asked on 11 Jan 2014, 02:36 PM
Hello Gurus,

    I need an example for Heirachical RadGrid with simple List<someentity>,(not with database,and not with Dataset).
  please can anyone provide the same with an example.

Thanks in Advance.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Jan 2014, 06:00 AM
Hi Prasanth,

Please take a look into the following code snippet I tried.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" Width="800px" OnNeedDataSource="RadGrid1_NeedDataSource"
    OnDetailTableDataBind="RadGrid1_DetailTableDataBind">
    <MasterTableView HierarchyLoadMode="ServerBind">
        <DetailTables>
            <telerik:GridTableView>
            </telerik:GridTableView>
        </DetailTables>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        List<Order> orders = new List<Order>();
        for (int i = 0; i < 5; i++)
        {
            Order order = new Order();
            order.Id = i;
            order.ListOrderDetail = new List<OrderDetail>();
            for (int j = 0; j < 3; j++)
            {
                OrderDetail detail = new OrderDetail();
                detail.Article = String.Format("Order {0} Detail {1} Article Text", i, j);
                detail.Qte = 10 % (j + 1);
                detail.Price = 10d / (j + 1);
 
                order.ListOrderDetail.Add(detail);
            }
 
            orders.Add(order);
        }
 
        RadGrid1.DataSource = orders;
    }
 
    protected void RadGrid1_DetailTableDataBind(object sende, GridDetailTableDataBindEventArgs e)
    {
        e.DetailTableView.DataSource = ((OrderData)e.DetailTableView.ParentItem.DataItem).ListOrderDetail;
    }
 
public class Order
{
    public Order()
    {
    }
 
    public int Id { get; set; }
    public List<OrderDetail> ListOrderDetail { get; set; }
}
public class OrderDetail
{
    public OrderDetail()
    {
    }
    public string Article { get; set; }
    public int Qte { get; set; }
    public double Price { get; set; }
    public double PriceHT { get { return Qte * Price; } }
}

Thanks,
Princy.
0
Prasanth100
Top achievements
Rank 1
answered on 23 Jan 2014, 07:58 PM
Thank you Princy,you made it ver simple. it works perfect.
Tags
Grid
Asked by
Prasanth100
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Prasanth100
Top achievements
Rank 1
Share this question
or