Back to Devexpress

GridViewSettings.InitNewRow Property

aspnetmvc-devexpress-dot-web-dot-mvc-dot-gridviewsettings-c0d4e145.md

latest3.1 KB
Original Source

GridViewSettings.InitNewRow Property

Enables you to initialize added rows.

Namespace : DevExpress.Web.Mvc

Assembly : DevExpress.Web.Mvc5.v25.2.dll

NuGet Package : DevExpress.Web.Mvc5

Declaration

csharp
public ASPxDataInitNewRowEventHandler InitNewRow { get; set; }
vb
Public Property InitNewRow As ASPxDataInitNewRowEventHandler

Property Value

TypeDescription
ASPxDataInitNewRowEventHandler

A delegate method that allows you to specify initial values.

|

Remarks

The initialization of a new row added to the GridView occurs when:

Use the argument’s NewValues property to specify the values in the new row.

csharp
@Html.DevExpress().GridView(settings => {
    settings.Name = "GridView";

    // ...
    settings.KeyFieldName = "CustomerID";
    settings.Columns.Add("CompanyName");
    settings.Columns.Add("ContactName");
    settings.Columns.Add("ContactTitle");
    settings.Columns.Add("Phone");
    // Process the initialization of new rows.
    settings.InitNewRow = (s, e) => {
        e.NewValues["Phone"] = "(5) 555-12-34";
        e.NewValues["ContactTitle"] = "Owner";
    };
}).Bind(Model).GetHtml()

The image below illustrates the edit form that appears after a user clicks the New button.

Note that you can initialize values only for those columns that are visible within the Edit Form or In-Line Edit Row. To specify values of hidden columns, modify the properties of a model object passed to an action method specified via the MVCxGridViewEditingSettings.AddNewRowRouteValues property.

Online Example

View Example: How to implement row clone functionality

See Also

Declaring Server-Side Event Handlers

AddNewRowRouteValues

Initializing New Rows

Grid View

GridViewSettings Class

GridViewSettings Members

DevExpress.Web.Mvc Namespace