Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
select

Grid / LinqToSql Operations

Next database reset in 0 hours, 48 minutes, 22 seconds
Add new recordRefresh
 Category IDCategory NameDescription  
1BeveragesSoft drinks, coffees, teas, beers, and ales
2CondimentsSweet and savory sauces, relishes, spreads, and seasonings
 
Add new recordRefresh
 Product IDProduct NamePriceUnits In Stock 
1
Page size:
select
 7 items in 1 pages
15Genen Shouyu$15.5039
44Gula Malacca$19.4527
61Sirop d'érable$28.50113
63Vegie-spread$43.9024
65Louisiana Fiery Hot Pepper Sauce$21.0576
66Louisiana Hot Spiced Okra$17.004
77Original Frankfurter grüne Soße$13.0032
3ConfectionsDesserts, candies, and sweet breads
4Dairy ProductsCheeses
5Grains/CerealsBreads, crackers, pasta, and cereal
7ProduceDried fruit and bean curd
8SeafoodSeaweed and fish

  • The current example demonstrates RadGrid's capability for inserting new data, updating existing data and deleting data against an LinqDataSource. The only thing that is required of you is to configure the entity data source by incuding the correpsonding database tables in the linq to sql data model and set the following properties of the grid to true to propagate automatic update/insert/delete operations:

    • AllowAutomaticUpdates
    • AllowAutomaticInserts
    • AllowAutomaticDeletes

    What is on this example:
    • You can insert a new item using the [Add new record] button in the Command row.
    • You can edit an item using the Edit button (the first button in each row).
    • You can delete an item, using the Delete button (at the end of each row).

    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.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="VB" CodeFile="defaultvb.aspx.vb" AutoEventWireup="false" Inherits="Telerik.GridExamplesVBNET.DataEditing.LinqDataSource.DefaultVB" %>

    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag ID="Headtag1" runat="server"></qsf:HeadTag>
        <style type="text/css">
            .productDetails
            {
                list-style-type: none;
                padding-top:15px;
                list-style-image: none;
            }
            .productDetails label
            {
                display: inline-block;
                font-weight: bold;
                width: 100px;
            }
            .productDetails li
            {
                padding-bottom: 5px;
            }
            .productDetails li label
            {
                vertical-align: top;
            }
        </style>
    </head>
    <body class="BODY">
        <form id="form1" runat="server">
            <div>
                <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
                <qsf:Header ID="Header1" runat="server" NavigationLanguage="VB" ShowDbResetTimer="true">
                </qsf:Header>
                <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
                    <AjaxSettings>
                        <telerik:AjaxSetting AjaxControlID="RadGrid1">
                            <UpdatedControls>
                                <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                                <telerik:AjaxUpdatedControl ControlID="RadWindowManager1" />
                            </UpdatedControls>
                        </telerik:AjaxSetting>
                    </AjaxSettings>
                </telerik:RadAjaxManager>
                <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" />
                <telerik:RadGrid runat="server" ID="RadGrid1" DataSourceID="LinqDataSource1" AllowAutomaticUpdates="true"
                    AllowAutomaticInserts="true" AllowAutomaticDeletes="true" AutoGenerateColumns="false"
                    AllowPaging="true">
                    <MasterTableView DataKeyNames="CategoryID" CommandItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage" AllowPaging="false">
                        <Columns>
                            <telerik:GridBoundColumn DataField="CategoryID" HeaderText="Category ID" ReadOnly="true"
                                ForceExtractValue="Always" />
                            <telerik:GridBoundColumn DataField="CategoryName" HeaderText="Category Name" />
                            <telerik:GridBoundColumn DataField="Description" HeaderText="Description" />
                            <telerik:GridEditCommandColumn ButtonType="ImageButton" />
                            <telerik:GridButtonColumn ConfirmText="Delete this category?" ConfirmDialogType="RadWindow"
                                ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
                        </Columns>
                        <DetailTables>
                            <telerik:GridTableView DataSourceID="LinqDataSource2" CommandItemDisplay="Top" DataKeyNames="ProductID, CategoryID"
                                Width="100%" InsertItemPageIndexAction="ShowItemOnCurrentPage" EditMode="PopUp">
                                <ParentTableRelation>
                                    <telerik:GridRelationFields DetailKeyField="CategoryID" MasterKeyField="CategoryID" />
                                </ParentTableRelation>
                                <Columns>
                                    <telerik:GridEditCommandColumn ButtonType="ImageButton" />
                                    <telerik:GridBoundColumn DataField="ProductID" HeaderText="Product ID" ReadOnly="true"
                                        ForceExtractValue="Always" />
                                    <telerik:GridBoundColumn DataField="CategoryID" HeaderText="CategoryID" ReadOnly="true"
                                        ForceExtractValue="Always" Visible="false" />
                                    <telerik:GridBoundColumn DataField="ProductName" HeaderText="Product Name" />
                                    <telerik:GridBoundColumn DataField="UnitPrice" HeaderText="Price" DataFormatString="{0:c}" />
                                    <telerik:GridNumericColumn DataField="UnitsInStock" HeaderText="Units In Stock" NumericType="Number" />
                                    <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                                        ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
                                </Columns>
                                <EditFormSettings EditFormType="WebUserControl" UserControlName="productdetailsvb.ascx">
                                    <EditColumn ButtonType="ImageButton" />
                                    <PopUpSettings Modal="true" Width="350px" />
                                </EditFormSettings>
                            </telerik:GridTableView>
                        </DetailTables>
                        <EditFormSettings>
                            <EditColumn ButtonType="ImageButton" />
                            <PopUpSettings Modal="true" />
                        </EditFormSettings>
                    </MasterTableView>
                    <PagerStyle AlwaysVisible="true" />
                </telerik:RadGrid>
                <telerik:RadWindowManager ID="RadWindowManager1" runat="server" />
    <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="LinqToSql.NorthwindDataContext"
    EnableDelete="True" EnableInsert="True" EnableUpdate="True" TableName="Categories">

                </asp:LinqDataSource>
    <asp:LinqDataSource ID="LinqDataSource2" runat="server" ContextTypeName="LinqToSql.NorthwindDataContext"
    EnableDelete="True" EnableInsert="True" EnableUpdate="True" TableName="Products"
    Where="CategoryID == @CategoryID">

                    <WhereParameters>
                        <asp:Parameter Name="CategoryID" Type="Int32" />
                    </WhereParameters>
                </asp:LinqDataSource>
                <qsf:Footer ID="Footer1" runat="server"></qsf:Footer>
            </div>
        </form>
    </body>
    </html>

Get more than expected!

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2012 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451