Intersoft WebGrid Documentation
Walkthrough: Creating Updatable Hierarchical WebGrid using ISDataSource
See Also Send comments on this topic.

Glossary Item Box

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:

 Prerequisites

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

  • Access to the Microsoft Access Northwind database.
  • Visual Studio 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.NET 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 OrderID, string CustomerID, Nullable EmployeeID, Nullable OrderDate,Nullable RequiredDate, Nullable ShippedDate, Nullable ShipVia, Nullable 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.

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.