# DataGrid - How to add a new row below previous one?

**URL:** <https://forum.radzen.com/t/datagrid-how-to-add-a-new-row-below-previous-one/18387>\
**Category:** Radzen.Blazor Components\
**Created:** [September 6, 2024, 2:27pm UTC](https://forum.radzen.com/t/datagrid-how-to-add-a-new-row-below-previous-one/18387 "2024-09-06T14:27:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robot](https://forum.radzen.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@Robot](https://forum.radzen.com/u/Robot)\
**Post date:** [September 6, 2024, 2:27pm UTC](https://forum.radzen.com/t/datagrid-how-to-add-a-new-row-below-previous-one/18387/1 "2024-09-06T14:27:52Z")

</div>

Hello,

Is it possible to add a new row to a data grid below the previous one?

[Data grid adding a new row](https://streamable.com/l0866t)

```auto
<RadzenFieldset Text="Proforma Invoices">
    <RadzenButton ButtonStyle="ButtonStyle.Success" Icon="add_circle" Text="Add" Click="@InsertRow" Disabled="@(editMode == DataGridEditMode.Single && proformasToInsert.Count() > 0)" />
    <RadzenDataGrid @ref="proformaGrid" AllowAlternatingRows="false" AllowFiltering="false" AllowPaging="false" PageSize="1" AllowSorting="false" EditMode="DataGridEditMode.Single"
                        Data="@proformaInvoices" TItem="ProformaInvoice" RowUpdate="@OnUpdateRow" RowCreate="@OnCreateRow">

        <Columns>
            <RadzenDataGridColumn TItem="ProformaInvoice" Property="orderNumber" Title="Order Number">
                <EditTemplate Context="item">
                    <RadzenTextBox @bind-Value="item.orderNumber" Style="width:200px; display: block" Name="Order Number" aria-label="Enter Order Number" />
                </EditTemplate>
            </RadzenDataGridColumn>
            <RadzenDataGridColumn TItem="ProformaInvoice" Property="responsible" Title="Responsible">
                <EditTemplate Context="item">
                    <RadzenTextBox @bind-Value="item.responsible" Style="width:200px; display: block" Name="Responsible" aria-label="Enter Responsible" />
                </EditTemplate>
            </RadzenDataGridColumn>
            <RadzenDataGridColumn TItem="ProformaInvoice" Property="product" Title="Product">
                <EditTemplate Context="item">
                    <RadzenTextBox @bind-Value="item.product" Style="width:200px; display: block" Name="Product" aria-label="Enter Product" />
                </EditTemplate>
            </RadzenDataGridColumn>
            <RadzenDataGridColumn TItem="ProformaInvoice" Property="productCode" Title="Product Code"/>
            <RadzenDataGridColumn TItem="ProformaInvoice" Property="productDescription" Title="Product Description"/>
            <RadzenDataGridColumn TItem="ProformaInvoice" Property="productPrice" Title="Product Price" />
                <RadzenDataGridColumn TItem="ProformaInvoice" Context="item" Filterable="false" Sortable="false" TextAlign="TextAlign.Right" >
               <EditTemplate Context="item">
                    <RadzenButton Icon="check" ButtonStyle="ButtonStyle.Success" Variant="Variant.Flat" Size="ButtonSize.Medium" Click="@((args) => SaveRow(item))" aria-label="Save">
                    </RadzenButton>
                    <RadzenButton Icon="close" ButtonStyle="ButtonStyle.Light" Variant="Variant.Flat" Size="ButtonSize.Medium" class="rz-my-1 rz-ms-1" Click="@((args) => CancelEdit(item))" aria-label="Cancel">
                    </RadzenButton>
                    
                </EditTemplate>
            </RadzenDataGridColumn>
        </Columns>
    </RadzenDataGrid>
</RadzenFieldset>

```

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [September 6, 2024, 2:30pm UTC](https://forum.radzen.com/t/datagrid-how-to-add-a-new-row-below-previous-one/18387/2 "2024-09-06T14:30:44Z")

</div>

You can add item to the collection bound to the DataGrid Data and Reload() the grid.

---

<div class="post-metadata">

**Author:** ![Robot](https://forum.radzen.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@Robot](https://forum.radzen.com/u/Robot)\
**Post date:** [September 7, 2024, 4:11am UTC](https://forum.radzen.com/t/datagrid-how-to-add-a-new-row-below-previous-one/18387/3 "2024-09-07T04:11:55Z")

</div>

I added the collection to the data grid data and reloaded but all data disappeared. What is wrong with it?

[Data grid](https://streamable.com/v40nxj)

```auto

RadzenDataGrid<ProformaInvoice> proformaGrid;
List<ProformaInvoice> proformasToInsert = new List<ProformaInvoice>();
List<ProformaInvoice> proformasToUpdate = new List<ProformaInvoice>();
List<ProformaInvoice> proformaList = new List<ProformaInvoice>();

DataGridEditMode editMode = DataGridEditMode.Single;
IEnumerable<ProformaInvoice> proformaInvoices;

public class Order
{
    public int CardId { get; set; }
    public string CardNr { get; set; }
    public DateTime ExpiryDate { get; set; }
    public string CardHolder { get; set; }
    public string Name { get; set; }
    public string Address1 { get; set; }
    public string Address2 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Zip { get; set; }
    public int Country { get; set; }
    public int StoreId { get; set; }
    public string Warehouse { get; set; }
    public string Region { get; set; }
    public string System { get; set; }
    public int TransId { get; set; }
    public string Register { get; set; }
    public string Clerk { get; set; }
    public decimal Amount { get; set; }
    public decimal Tax { get; set; }
    public DateTime OrderDate { get; set; }
    public DateTime ShipDate { get; set; }
    public IEnumerable<ProformaInvoice> ProformaInvoices { get; set; }
}

public class ProformaInvoice
{
    public string orderNumber { get; set; }
    public string responsible { get; set; }
    public string product { get; set; }
    public string productCode { get; set; }
    public string productDescription { get; set; }
    public string productPrice { get; set; }
    public List<string> products { get; set; }
}
Order order = new Order()
    {
        ExpiryDate = DateTime.Parse("10/10/2022"),
        OrderDate = DateTime.Now,
        ShipDate = DateTime.Now,
        ProformaInvoices = new List<ProformaInvoice>()
    };

async Task InsertRow()
{
    if (editMode == DataGridEditMode.Single)
    {
        Reset();
    }
    var proformas = new ProformaInvoice();
    proformasToInsert.Add(proformas);
    await proformaGrid.InsertRow(proformas);
}

void OnCreateRow(ProformaInvoice item)
{
    proformasToInsert.Remove(item);
}
void Reset()
{
    proformasToInsert.Clear();
    proformasToUpdate.Clear();

}

void Reset(ProformaInvoice item)
{
    proformasToInsert.Remove(item);
    proformasToUpdate.Remove(item);
}
async Task SaveRow(ProformaInvoice item)
{
    await proformaGrid.UpdateRow(item);
    proformaList.Add(item);
    order.ProformaInvoices = proformaList.OrderBy(p => p.orderNumber).ToList();

    await proformaGrid.Reload();
}

void OnUpdateRow(ProformaInvoice item)
{
    Reset(item);
   
}

void CancelEdit(ProformaInvoice item)
{
    Reset(item);

    proformaGrid.CancelEditRow(item);

    
}

protected override async Task OnInitializedAsync()
{
    proformaInvoices = new List<ProformaInvoice>();
}

```

---

<div class="post-metadata">

**Author:** ![Robot](https://forum.radzen.com/letter_avatar_proxy/v4/letter/r/7993a0/32.png) [@Robot](https://forum.radzen.com/u/Robot)\
**Post date:** [September 7, 2024, 4:57pm UTC](https://forum.radzen.com/t/datagrid-how-to-add-a-new-row-below-previous-one/18387/4 "2024-09-07T16:57:46Z")

</div>

This works.

```auto
async Task SaveRow(ProformaInvoice item)
{
    await proformaGrid.UpdateRow(item);
    proformaList.Add(item);
    proformaList = proformaList.OrderBy(p => p.orderNumber).ToList();
    proformaInvoices = proformaList;
    order.ProformaInvoices = proformaList;
    await proformaGrid.Reload();
}

```
