telerik

Submission
Home  Community  CodeLibrary home  RadControls for ASP.NET and ASP.NET AJAX  RadGrid  Automatic operations in hierarchical grid with SqlDataSource control

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.