Automatic operations in hierarchical grid with SqlDataSource control

Thread is closed for posting
5 posts, 1 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 05 Feb 2007 Link to this post


    RadGrid for ASP .NET version

    RadControls for ASP .NET AJAX version
    4.x and later

    2008.1.415 and later
    .NET version

    2.0 and later

    Visual Studio version

    2005 and later

    Programming language

    Codeless data-binding, C#

    Browser support

    all supported by RadGrid for ASP .NET

    all browsers supported by RadControls for ASP .NET AJAX


    This demo represents how to perform automatic operations (update/insert/delete) in hierarchical grid with SqlDataSource control (introduced in ASP.NET 2.0). The main points are:
    • enable the automatic operations for the grid
    • configure from design-time the update/insert/delete parameters of the SqlDataSource controls (one for each level in the hierarchy).
    • since the Select command of the data source control is fired before the Insert command (you can verify that by wiring the Inserted/Selected events for one of the SqlDataSource controls), you need to hook the InsertCommand event of the grid and define the parent key field for newly inserted detail row manually.

      Below is the VB.NET version of the code:

      Protected Sub RadGrid1_InsertCommand(ByVal source As ObjectByVal e As GridCommandEventArgs) Handles RadGrid1.InsertCommand  
         Dim parentItem As GridDataItem = CType(e.Item.OwnerTableView.ParentItem, GridDataItem)   
         nestedTableSource.InsertParameters("EmployeeID").DefaultValue = parentItem.OwnerTableView.DataKeyValues(parentItem.ItemIndex)("EmployeeID").ToString()   
      End Sub 

    Note that you may need to modify the connection string (NorthwindConnectionString) in the web.config file of the web site to point to the Northwind SQL database. The database is present under the App_Data subfolder.

    Feel free to extend the example if more nested levels need to be added.

  2. 5F935FA1-2007-46C7-98A4-A5CA6435DD38
    5F935FA1-2007-46C7-98A4-A5CA6435DD38 avatar
    44 posts
    Member since:
    Sep 2008

    Posted 13 Nov 2008 Link to this post

    Thank you fro this. I've been battling and this is the perfect solution, with example and all!
    NIce work.
  3. 23C72464-8FC9-43C3-9A12-B431B37B7758
    23C72464-8FC9-43C3-9A12-B431B37B7758 avatar
    11 posts
    Member since:
    Dec 2013

    Posted 13 Nov 2008 Link to this post

    Hi Darren,

    Indeed, the code library section contains a large number of custom projects, and custom solutions. In addition to searching in it for different projects, you can also post your own custom implementations as well, if you believe the community will benefit from them.
    Good luck with your work!

    Best wishes,
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  4. 8FD57FAA-6888-4360-901B-88CCDB1E9A54
    8FD57FAA-6888-4360-901B-88CCDB1E9A54 avatar
    3 posts
    Member since:
    May 2009

    Posted 28 May 2009 Link to this post

    can you please give me the c# version of this code.
  5. Answer
    8FD57FAA-6888-4360-901B-88CCDB1E9A54 avatar
    3 posts
    Member since:
    May 2009

    Posted 28 May 2009 Link to this post

    c# version
    protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
                GridDataItem parentItem = (GridDataItem)e.Item.OwnerTableView.ParentItem;
                nestedTableSource.InsertParameters["EmployeeID"].DefaultValue = parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["EmployeeID"].ToString();
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.