Skip to main content
Tab

DataViewItemCollection.Add() Method

Adds a new item to the end of the collection.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v23.2.dll

NuGet Package: DevExpress.Web

Declaration

public DataViewItem Add()

Returns

Type Description
DataViewItem

A DataViewItem object that has been added to the collection.

Remarks

This method creates a new DataViewItem object, initializes it with default settings and appends it to the collection.

Use the Add method to add data items in code-behind. In this case, a custom data object with the required properties should be assigned to the DataViewItem.DataItem property value.

using DevExpress.Web;
    const int itemsCount = 10;
    protected void DataView_Load(object sender, System.EventArgs e) {
        AddDataItems(DataView);
        DataView.ItemTemplate = new MyDataViewTemplate();
    }
    void AddDataItems(ASPxDataView dataView) {
        for (int i = 1; i <= itemsCount; i++) {
            dataView.Items.Add().DataItem = new {
                ID = i,
                Name = "Name" + i,
                Description = "Sample description for the item"
            };
        }
    }
See Also