Step 17: Adding Items to the Order Detail GridView

The standard .NET Web Forms GridView does 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:

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

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

    protected void btnAddDetail_Click(object sender, EventArgs e)
    {
    	// Retrieve the previous Order Detail Entity List
    	mmBindingList<OrderDetailEntity> orderDetailList = this.GetEntityListFromSession<OrderDetailEntity>("CurrentOrderDetail");
     
    	// Add a new entity to the Entity List
    	this.OrderDetail.NewEntity(orderDetailList, new OrderDetailDefaults(this.OrderID));
     
    	// Store the Entity List back into the session
    	this.StoreEntityListInSession<OrderDetailEntity>(orderDetailList, "CurrentOrderDetail");
     
    	// Set the new row for editing
    	this.grdOrderDetail.EditIndex = orderDetailList.Count - 1;
     
    	// Rebind the GridView
    	this.BindControl(this.grdOrderDetail);
    }

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

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