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.
Version Q1 2012 released 04/11/2012
select

Grid / Edit on Double-click

Next database reset in 0 hours, 49 minutes, 8 seconds
ProductIDProduct nameQuantityUnitPriceIn stockDiscontinued
Page size:
select
 63 items in 9 pages
7Uncle Bob's Organic Dried Pears12 - 1 lb pkgs.$30.0015
10Ikura12 - 200 ml jars$31.0031
12Queso Manchego La Pastora10 - 500 g pkgs.$38.0086
13Konbu2 kg box$6.0024
14Tofu40 - 100 g pkgs.$23.2535
15Genen Shouyu24 - 250 ml bottles$15.5039
16Pavlova32 - 500 g boxes$17.4529



  • You may want to allow the user to force grid item in edit mode by simply double-clicking the respective item (an easy and intuitive approach). This demo illustrates how to switch a row in edit mode by double-clicking an arbitrary grid item and how to update this row when the user clicks another row in the grid. Furthermore, a user-friendly confirm dialog will be displayed to prompt whether the operation should be propagated or not.

    The example uses RadAjaxManager instance to ajaxify the grid and perform RadAjaxManagerClientObject.ajaxRequest() calls. These calls are invoked through the RowClick and RowDblClick events) and the onchange event of the inputs in the grid rows used for editing (the handler for the onchange event is assigned in the GridCreated handler of the grid).

Source Code

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

    <%@ Register TagPrefix="telerik" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="telerik" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!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">
        <telerik:HeadTag runat="server" ID="Headtag2"></telerik:HeadTag>
    </head>
    <body class="BODY">
        <form runat="server" id="mainForm" method="post">
            <telerik:Header runat="server" ID="Header1" NavigationLanguage="VB" ShowDbResetTimer="true"></telerik:Header>
            <!-- content start -->
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
            <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">
            <!--
             var hasChanges, inputs, dropdowns, editedRow;
                
             function RowClick(sender, eventArgs)
             {
                 if(editedRow && hasChanges)
                 {
                 hasChanges = false;
                     if(confirm("Update changes?"))
                     {
                        
                         $find("<%= RadGrid1.ClientID %>").get_masterTableView().updateItem(editedRow);
                     }
                 }
             }

             function RowDblClick(sender, eventArgs)
             {
                 editedRow = eventArgs.get_itemIndexHierarchical();
                 $find("<%= RadGrid1.ClientID %>").get_masterTableView().editItem(editedRow);
             }

                function GridCommand(sender, args)
             {
             if (args.get_commandName() != "Edit")
             {
             editedRow = null;
             }
             }

             function GridCreated(sender, eventArgs)
             {
             var gridElement = sender.get_element();
             var elementsToUse = [];
                 inputs = gridElement.getElementsByTagName("input");
                 for (var i = 0; i < inputs.length;i++)
                 {
                 var lowerType = inputs[i].type.toLowerCase();
                 if(lowerType == "hidden" || lowerType == "button")
                 {
                            continue;
                 }
                    
                 Array.add(elementsToUse, inputs[i]);
                     inputs[i].onchange = TrackChanges;
                 }
                    
                 dropdowns = gridElement.getElementsByTagName("select");
                 for (var i = 0; i < dropdowns.length;i++)
                 {
                     dropdowns[i].onchange = TrackChanges;
                 }

                 setTimeout(function(){if(elementsToUse[0])elementsToUse[0].focus();},100);
             }

             function TrackChanges(e)
             {
                 hasChanges = true;
             }
         -->    
        </script>
        </telerik:RadCodeBlock>
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                            <telerik:AjaxUpdatedControl ControlID="Label1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" Width="97%"
                ShowStatusBar="True" AllowSorting="True" PageSize="7" GridLines="None" AllowPaging="True"
                runat="server" AllowAutomaticUpdates="True" AutoGenerateColumns="False">
                <MasterTableView TableLayout="Fixed" DataKeyNames="ProductID" EditMode="InPlace">
                  <Columns>
                    <telerik:GridBoundColumn UniqueName="ProductID" DataField="ProductID" HeaderText="ProductID" ReadOnly="True" HeaderStyle-Width="10%" />
                    <telerik:GridBoundColumn UniqueName="ProductName" DataField="ProductName" HeaderText="Product name"
                     HeaderStyle-Width="25%" ColumnEditorID="GridTextBoxColumnEditor1" />
                    <telerik:GridBoundColumn UniqueName="QuantityPerUnit" DataField="QuantityPerUnit" HeaderText="Quantity"
                     HeaderStyle-Width="20%" />
                    <telerik:GridNumericColumn UniqueName="UnitPrice" DataField="UnitPrice" HeaderText="UnitPrice"
                     DataFormatString="{0:C}" HeaderStyle-Width="10%" />
                    <telerik:GridDropDownColumn UniqueName="UnitsInStock" HeaderText="In stock" ColumnEditorID="GridDropDownListColumnEditor1"
                     ListTextField="UnitsInStock" ListValueField="UnitsInStock" DataSourceID="SqlDataSource1" DataField="UnitsInStock" HeaderStyle-Width="10%" />
                    <telerik:GridCheckBoxColumn UniqueName="Discontinued" DataField="Discontinued" HeaderText="Discontinued"
                     HeaderStyle-Width="10%" ColumnEditorID="GridCheckBoxColumnEditor1" />
                  </Columns>
                </MasterTableView>
                <ClientSettings>
                    <ClientEvents OnRowClick="RowClick" OnRowDblClick="RowDblClick"
                        OnGridCreated="GridCreated" OnCommand="GridCommand" />
                </ClientSettings>
            </telerik:RadGrid>
            <telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server" TextBoxStyle-Width="180px" />
            <telerik:GridDropDownListColumnEditor ID="GridDropDownListColumnEditor1" runat="server" DropDownStyle-Width="70px" />
            <telerik:GridCheckBoxColumnEditor ID="GridCheckBoxColumnEditor1" runat="server" CheckBoxStyle-BorderWidth="2" />
            <br />
            <asp:Label ID="Label1" runat="server" EnableViewState="false" />
            <br />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString35 %>"

                SelectCommand="SELECT * FROM [Products]"
                UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [QuantityPerUnit] = @QuantityPerUnit, [UnitPrice] = @UnitPrice, [UnitsInStock] = @UnitsInStock, [Discontinued] = @Discontinued WHERE [ProductID] = @ProductID">
                <UpdateParameters>
                    <asp:Parameter Name="ProductName" Type="String" />
                    <asp:Parameter Name="QuantityPerUnit" Type="String" />
                    <asp:Parameter Name="UnitPrice" Type="Decimal" />
                    <asp:Parameter Name="UnitsInStock" Type="Int16" />
                    <asp:Parameter Name="Discontinued" Type="Boolean" />
                    <asp:Parameter Name="ProductID" Type="Int32" />
                </UpdateParameters>
            </asp:SqlDataSource>
            <!-- content end -->
            <telerik:Footer runat="server" ID="Footer1"></telerik:Footer>
        </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