Search code examples
axaptadynamics-ax-2009enterprise-portal

How to enable create / insert in a AxGridView in Enterprise Portal (Dynamics AX 2009)


There must be a way to enable creation and insertion of a record from a AxGridView without using the Tunnel and Wizard approach. From what I have found on the Internet so far, the only example is using a Wizard, and I honestly don't find that to be a user friendly approach.

Has anyone tried to enable insertion of records directly from a AxGridView?


Solution

  • Yes it is possible to enter data through AxGridView. Just enable Editing, deleting for that control. And one more thing to make new row - you have to make addditional button - create new line, and code behind:

    protected void NewLine_Click(object sender, EventArgs e)
    {
        int editIdx = AxGridView1.EditIndex;      
    
        try
        {
            // Save the last unsaved line if any
            if (AxGridView1.EditIndex != -1 && AxGridView1.Rows.Count > 0)
            {
                this.AxGridView1.UpdateRow(AxGridView1.EditIndex, true); 
            }
    
    
            DataSetViewRow dsvr = this.dsv.AddNew();        
        }
        catch (System.Exception ex)
        {
            AxExceptionCategory exceptionCategory;
    
            if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
            {
                // Throw the fatal exception
                throw;
            }
            if (exceptionCategory == AxExceptionCategory.NonFatal)
            {
                AxGridView1.EditIndex = editIdx;
            }
        }
    }
    
    private DataSetView dsv //get dataset view
        {
            get
            {
                DataSet dataSet = this.AxDataSource1.GetDataSet();
                return dataSet.DataSetViews[this.AxGridView1.DataMember];
            }
        }