Automatic operations in hierarchical grid with SqlDataSource control

Thread is closed for posting
5 posts, 1 answers
  1. Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 05 Feb 2007 Link to this post

    Requirements

    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


    PROJECT DESCRIPTION

    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. Darren
    Darren 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. Yavor
    Admin
    Yavor avatar
    11 posts

    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,
    Yavor
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  4. ranjana
    ranjana 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
    ranjana
    ranjana 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