New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

CRUD Operations with EntityDataSource

Next database reset in 1 hours, 19 minutes, 40 seconds
 IDCategoriesParent ID
1
Page size:
 60cv 
  • Edit Mode Configurator

This example illustrates how automatic insert, update and delete data operations can be achieved with RadTreeList and all ASP 3.5 DataSource control types like EntityDataSource:

What you need to do is to set the following properties:

  • DataSourceID property of the RadTreeList to the ID of the Data Source control
  • EnableUpdate, EnableInsert, EnableDelete properties of the Data Source control to true
  • DataKeyNames and ParentDataKeyNames properties of RadTreeList by listing the data source table Primary keys

The RadTreelist control expects the key to be incremented when you insert items, therefore the new items are located at the bottom of the group.

You may also see how to utilize Telerik OpenAccess ORM as a data access layer for our AJAX controls by visiting the OpenAccess ORM live demos here.

  • DefaultCS.aspx
  • DefaultCS.aspx.cs
<%@ Page Language="c#" CodeFile="~/TreeList/Examples/DataEditing/Net35AutomaticDataEditing/DefaultCS.aspx.cs"Inherits="Telerik.Web.Examples.TreeList.DataEditing.NET35AutomaticDataEditing.DefaultCS"  %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
    <style type="text/css">
        .MyImageButton {
            cursor: pointer;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <div class="demo-container no-bg">
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel>
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" LoadingPanelID="RadAjaxLoadingPanel1" runat="server">

            <telerik:RadTreeList RenderMode="Lightweight" runat="server" ID="RadTreeList1" DataSourceID="EntityDataSource1" AllowPaging="true" PageSize="5" DataKeyNames="id" ParentDataKeyNames="parentId" AutoGenerateColumns="false">
                <Columns>
                    <telerik:TreeListEditCommandColumn UniqueName="EditCommandColumn" ButtonType="FontIconButton" HeaderStyle-Width="120px">
                        <ItemStyle CssClass="MyImageButton"></ItemStyle>
                    </telerik:TreeListEditCommandColumn>
                    <telerik:TreeListButtonColumn UniqueName="DeleteCommandColumn" Text="Delete" CommandName="Delete" HeaderStyle-Width="60px" ButtonType="FontIconButton"></telerik:TreeListButtonColumn>
                    <telerik:TreeListBoundColumn DataField="id" UniqueName="id" HeaderText="ID" ReadOnly="true"></telerik:TreeListBoundColumn>
                    <telerik:TreeListBoundColumn DataField="Text" UniqueName="Categories" HeaderText="Categories"></telerik:TreeListBoundColumn>
                    <telerik:TreeListBoundColumn DataField="parentid" UniqueName="parentid" HeaderText="Parent ID" ReadOnly="true"></telerik:TreeListBoundColumn>
                </Columns>
            </telerik:RadTreeList>
        </telerik:RadAjaxPanel>
        <asp:EntityDataSource runat="server" ID="EntityDataSource1" ConnectionString="name=TelerikReadWriteEntities" DefaultContainerName="TelerikReadWriteEntities" EntitySetName="Links" EnableInsert="True" EnableUpdate="True" EnableDelete="True">
        </asp:EntityDataSource>
    </div>
    <qsf:ConfiguratorPanel runat="server" ID="ConfigurationPanel1" Title="Edit Mode Configurator" Expanded="true">
        <Views>
            <qsf:View>
                <qsf:ConfiguratorColumn runat="server" Size="Medium">
                    <qsf:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
                        <asp:ListItem Text="In-forms editing mode" Value="EditForms" Selected="True"></asp:ListItem>
                        <asp:ListItem Text="In-line editing mode" Value="InPlace"></asp:ListItem>
                        <asp:ListItem Text="Pop-up editing mode" Value="PopUp"></asp:ListItem>
                    </qsf:RadioButtonList>
                </qsf:ConfiguratorColumn>
            </qsf:View>
        </Views>
    </qsf:ConfiguratorPanel>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance