Telerik
Skip Navigation LinksHome / Community / Code Library / ASP.NET and ASP.NET AJAX > Grid > Automatic operations in hierarchical grid with SqlDataSource control

Answered Automatic operations in hierarchical grid with SqlDataSource control

Feed from this thread
  • Telerik Admin MVP avatar

    Posted on Feb 5, 2007 (permalink)

    Requirements

    RadGrid version

    4.x or Telerik.Web.UI 2007.12.18+

    .NET version

    2.x

    Visual Studio version

    2005

    programming language

    codeless data-binding, C#

    browser support

    all browsers supported by RadGrid


     
  • 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.

  • Darren Darren's avatar

    Posted on Nov 13, 2008 (permalink)

    Thank you fro this. I've been battling and this is the perfect solution, with example and all!
    NIce work.

  • Telerik Admin admin's avatar

    Posted on Nov 13, 2008 (permalink)

    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.

  • ranjana avatar

    Posted on May 28, 2009 (permalink)

    can you please give me the c# version of this code.

  • Answer ranjana avatar

    Posted on May 28, 2009 (permalink)

    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

    Skip Navigation LinksHome / Community / Code Library / ASP.NET and ASP.NET AJAX > Grid > Automatic operations in hierarchical grid with SqlDataSource control

    Powered by Sitefinity ASP.NET CMS

    Contact Us | Site Feedback | Terms of Use | Privacy Policy
    Copyright © 2002-2010 Telerik. All rights reserved.