New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

ClientDataSource Object - add()

Method which appends a new data item to the data source.

ParametersDescription
newValuesJSON formatted values to insert as a new item.
ASPNET
<telerik:RadClientDataSource runat="server" ID="RadClientDataSource1">
    <DataSource>
        <WebServiceDataSourceSettings ServiceType="OData">
            <Select Url="https://demos.telerik.com/aspnet-ajax/Services/SampleODataService.svc/Products" />
        </WebServiceDataSourceSettings>
    </DataSource>
    <Schema>
        <Model ID="ProductID"></Model>
    </Schema>
</telerik:RadClientDataSource>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="buttonClick(); return false;" />
JavaScript
<script type="text/javascript">
    var dataSource;
    function pageLoad() {
        dataSource = $find('<%= RadClientDataSource1.ClientID %>');
        dataSource.fetch();
    }
    function buttonClick() {
        var data = dataSource.view();
        var lastItem = data[data.length - 1];
        alert(lastItem.ProductName); // displays "Queso Manchego La Pastora"
        alert(lastItem.UnitPrice); // displays "6"

        dataSource.add({
            ProductName: "Success",
            UnitPrice: 9
        }, "1");

        var data = dataSource.view();
        var lastItem = data[data.length - 1];
        alert(lastItem.ProductName); // displays "Success"
        alert(lastItem.UnitPrice); // displays "9"
    }
</script>
Not finding the help you need?
Contact Support