Step 17 - Adding Items to the Order Detail GridView

The standard .NET Web Forms GridViewdoes not inherently have the ability to add records (there is no built-in "Add" button ), however in this step we will show you how to add this functionality manually.

  1. Place your cursor in the Order Detail GridView's parent table then press Enter twice to add two lines above the Order Detail GridView. Next, drag an mmButton from the Visual Studio ToolBox and drop it directly above the Order Detail GridView. For example:

    Change the Text property of the button to Add Detail and the (ID) property of the button to btnAddDetail.

  2. Double-click the Add Detail button which creates a btnAddDetail_Click event handler method to the form. Add the following code to this method:

    Private Sub btnAddDetail_Click(ByVal sender As System.Object, e As System.EventArgs) Handles btnAddDetail.Click
    	' Retrieve the previous Order Detail Entity List
    	Dim orderDetailList  As mmBindingList(Of OrderDetailEntity) = Me.GetEntityListFromSession(Of OrderDetailEntity)("CurrentOrderDetail")
    	
    	' Add a new entity to the Entity List
    	Me.OrderDetail.NewEntity(orderDetailList, new OrderDetailDefaults(Me.OrderID))
    
    	' Store the Entity List back into the session
    	Me.StoreEntityListInSession(Of OrderDetailEntity)(orderDetailList, "CurrentOrderDetail")
    
    	' Set the new row for editing
    	Me.grdOrderDetail.EditIndex = orderDetailList.Count - 1
    
    	' Rebind the GridView
    	Me.BindControl(Me.grdOrderDetail)
    End Sub

Now when you click the Add Detail button at run time it adds a new item to the Order Detail DataGrid:

See also:
Step 18 - Testing Business Rules


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 04/25/18
Comment or report problem with topic