Intersoft Support Center

Create Updatable Hierarchical Data with Batch Update

This walkthrough shows you how to identity upon successive inserts by creating a new insert methods.

During this walkthrough, you will learn how to do the following:

  • Binding ISDataSource to a WebGrid
  • Create updatable Hierarchical WebGrid by returning new identity

 Prerequisites

In order to complete this walkthrough, you will need the following:

  • Access to the Microsoft Access Northwind database.
  • Visual Studio 2005/2008/2010 Application.

 Step-By-Step Instructions

To create new web application and bind WebGrid to ObjectDataSource

  1. Bind WebGrid to Hierarchical ISDataSource control.
  2. Right click WebGrid instance and choose WebGrid Designer.
  3. Enable the Editing – Batch Update features in WebGrid Component Designer.



  4. Create a DoInsert() method for each table which is used in the WebGrid and SelectIdentityQuery() function to retrieve the newly created ID, for example:
    C# Copy Code
    [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)] 
    public int DoInsert(ref Nullable<int> OrderID, string CustomerID, Nullable<int> EmployeeID, Nullable<system.datetime> OrderDate,
    
    Nullable<system.datetime> RequiredDate, Nullable<system.datetime> ShippedDate, Nullable<int> ShipVia, Nullable<decimal> Freight, string ShipName,
    string ShipAddress, string ShipCity, string ShipRegion, string ShipPostalCode, string ShipCountry) { this.Connection.Open(); // important int affectedRows = this.Insert(CustomerID, EmployeeID, OrderDate, RequiredDate, ShippedDate, ShipVia,
    Freight, ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry); int? identity = this.SelectIdentityQuery(); OrderID = identity; // pass the new identity into OrderID param this.Connection.Close(); return affectedRows; }
    public int SelectIdentityQuery() { OleDbCommand cmd = new OleDbCommand("SELECT @@IDENTITY", this.Connection); int newID = (int)cmd.ExecuteScalar(); return newID; }

  5. Update the parameters in insert function in the ISDataSource for the ID parameter, set the Direction property to InputOutput. This parameter is required to reflect the parameter signature of DoInsert method.





  6. Click OK.
  7. You are all set. Run the page in browser.
Previous Next