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

one level hierarchy grid insert/update/delete

1 Answer 24 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 06 Jun 2013, 09:27 AM
Hello

I am new to Rad grid. as per the client requirement i have to create one level Hierarchy grid with Insert/Update/Delete. I want to bind the grid using NeedDataSource event i don't want to use SqlDataSource. My main grid will get populated using one Data Table Customer and Child Grid Will get Populate using different Data table order e.g.
                   DTCustomer                  DTOrder
CustomerID Name ContactNumber CustomerID  OrderNumber  OrderAmount
1 ABC 12345   1       1    100
2 PQR 345   2       2    200
3 XYZ 1456   3       3    300

Please Let me know that how can I bind the grid on NeedDataSource Event so that it will display Customer Data as Parent and Order Data as a Child.
Also please let me know that how can i implement the server side  logic to Insert/Update/Delete data to respective tables.
i have refer the example given on  http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/threelevel/defaultcs.aspx
URL but i don't  want to use Automatic Insert/Update/Delete.


1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 06 Jun 2013, 12:15 PM
Hello,

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource"
        OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnInsertCommand="RadGrid1_InsertCommand">
        <MasterTableView DataKeyNames="ID" Name="Parent" CommandItemDisplay="Top">
            <Columns>
                <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="ID">
                </telerik:GridBoundColumn>
                <telerik:GridEditCommandColumn>
                </telerik:GridEditCommandColumn>
            </Columns>
            <DetailTables>
                <telerik:GridTableView Name="Child" CommandItemDisplay="Top">
                    <Columns>
                        <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="ID">
                        </telerik:GridBoundColumn>
                        <telerik:GridEditCommandColumn>
                        </telerik:GridEditCommandColumn>
                    </Columns>
                </telerik:GridTableView>
            </DetailTables>
        </MasterTableView>
    </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        dynamic data = new[] {
            new { ID = 1, Name ="Name1"},
            new { ID = 2, Name = "Name2"},
            new { ID = 3, Name = "Name3"},
             new { ID = 4, Name = "Name4"},
            new { ID = 5, Name = "Name5"}
        };
 
        RadGrid1.DataSource = data;
    }
 
    protected void RadGrid1_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
    {
        string parentID = e.DetailTableView.ParentItem.GetDataKeyValue("ID").ToString();
 
        dynamic data = new[] {
            new { ID = 1, Name ="Name" + parentID},
            new { ID = 2, Name = "Name"+parentID},
            new { ID = 3, Name = "Name"+parentID},
             new { ID = 4, Name = "Name"+parentID},
            new { ID = 5, Name = "Name"+parentID}
        };
    }
    protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
    {
        if (e.Item.OwnerTableView.Name == "Parent")
        {
            // Perform your Insert opration here
        }
        else if (e.Item.OwnerTableView.Name == "Child")
        {
            //Access parent ID
            string parentID = e.Item.OwnerTableView.ParentItem.GetDataKeyValue("ID").ToString();
            // Perform your Insert opration here
        }
    }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Rahul
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or