This is a migrated thread and some comments may be shown as answers.

How to get edited values client side when using inplace editing

1 Answer 73 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
John asked on 31 May 2012, 12:21 AM
I am trying to use the ASP.Net AJAX grid control with AJAX and web services only. I have run into a few problems with the inplace editing. Specifically, if I use the GridEditCommandColumn, clicking the edit button deletes the grid for some reason. If I add in a typical DataSourceID="SqlDataSource1" to the grid and master table, these buttons work as expected, but I don't want to depend on the SQlDataSource control, I would prefer to use AJAX and a web service. The other problem I had was trying to find the value of the edited inplace control after clicking the update button. I was only able to find the original value. I have attached code snippets below:

     <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
    <telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" GridLines="None" Width="740"
            AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True"
            Skin="Windows7" EnableEmbeddedSkins="false" AutoGenerateColumns="false"  >
            <Selecting CellSelectionMode="None" AllowRowSelect="True"></Selecting>
            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
            <Resizing AllowColumnResize="True" AllowRowResize="false" ResizeGridOnColumnResize="false"
                ClipCellContentOnResize="true" EnableRealTimeResize="false" AllowResizeToFit="true" />
            <ClientEvents OnRowSelected="rowSelected" OnCommand="RaiseCommand" />

    <MasterTableView AutoGenerateColumns="False" DataKeyNames="ICID" EditMode="InPlace" Width="530" FilterItemStyle-HorizontalAlign="Center" >
        <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>

        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
            <HeaderStyle Width="20px"></HeaderStyle>

        <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
            <HeaderStyle Width="20px"></HeaderStyle>

                    UpdateImageUrl="Skins/Windows7/Grid/Update.gif" >
                <ItemStyle CssClass="Button.Windows7" HorizontalAlign="Center" />
                <HeaderStyle Width="60" />
            <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                UniqueName="DeleteColumn" ImageUrl="Skins/Windows7/Grid/Delete.gif">
                <HeaderStyle Width="40" />
                <ItemStyle HorizontalAlign="Center" />

            <telerik:GridBoundColumn DataField="ICID" DataType="System.Int32"
                FilterControlAltText="Filter ICID column" HeaderText="ICID" ReadOnly="True"
                SortExpression="ICID" UniqueName="ICID">
                <HeaderStyle Width="120" HorizontalAlign="Center" />
                <ItemStyle HorizontalAlign="Center" />
            <telerik:GridBoundColumn DataField="Class"
                FilterControlAltText="Filter Class column" HeaderText="Class"
                SortExpression="Class" UniqueName="Class">
                <HeaderStyle Width="140" HorizontalAlign="Center"  />
                <ItemStyle HorizontalAlign="Center" />
            <telerik:GridBoundColumn DataField="Config"
                FilterControlAltText="Filter Config column" HeaderText="Config"
                SortExpression="Config" UniqueName="Config">
                <HeaderStyle Width="140" HorizontalAlign="Center" />
                <ItemStyle HorizontalAlign="Center" />
                DataField="Active" DataType="System.Boolean"
                FilterControlAltText="Filter Active column" HeaderText="Active"
                UniqueName="Active" >
                <HeaderStyle Width="60" HorizontalAlign="Center" />
                <ItemStyle HorizontalAlign="Center" />
            <telerik:GridBoundColumn DataField="TEC"
                FilterControlAltText="Filter TEC column" HeaderText="TEC" SortExpression="TEC"
                UniqueName="TEC" >
                <HeaderStyle Width="200" HorizontalAlign="Center" />
                <ItemStyle HorizontalAlign="Center" />

        <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>


<FilterMenu EnableImageSprites="False"></FilterMenu>

The Javascript:

      function UpdateGrid()
            var data = 1;
            PageMethods.GetData(data, callUpdateGrid, callError);

        function callUpdateGrid(result)
            if (null == result)
                alert('No Data');

            var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();

        function RaiseCommand(sender, eventArgs)
// *******************************'
// How do I get the new value from the edit control here?
// The value variable always returns the previous value.
// *******************************'

            //retrieve the current commandName and commandArgument
            var cmd = eventArgs.get_commandName();
            var arg = eventArgs.get_commandArgument();
            var result = String.format("CommandName: {0}, CommandArgument: {1}", cmd, arg);
            var value = '';
            if ('Page' != cmd)
                var grid = $find("<%= RadGrid1.ClientID %>");
                var mastertable = grid.get_masterTableView();
                ICID = getDataItemKeyValue(grid, mastertable.get_dataItems()[arg]);
                var row = mastertable.get_dataItems()[arg];
                value = mastertable.getCellByColumnUniqueName(row, "TEC").innerHTML;
            alert(result + ', ' + ICID + ', ' + value);

The codebehind:

        public static IList<Model> GetData(int arg)
            IList<Model> ilm = new List<Model>();

            ilm.Add( new Model() { Active = "true", Class = "ABC", Config = "A1", ICID = 1, TEC = "TEC1" });
            ilm.Add(new Model() { Active = "", Class = "DEF", Config = "A2", ICID = 2, TEC = "TEC2" });
            ilm.Add(new Model() { Active = "true", Class = "GHI", Config = "A3", ICID = 3, TEC = "TEC3" });

            return ilm;

Can you tell me how to get inplace editing to work with the code above, and how to get the new values from the edited controls?


1 Answer, 1 is accepted

Sort by
Telerik team
answered on 04 Jun 2012, 07:23 AM
Hi John,

Unfortunately the RadGrid does not support the desired functionality. In order to show the Edit form of the grid you need a post back to the server. In this case the post back is required because the edit form of the RadGrid needs to extract all values from the edited item. Also the Edit Form could contain other script controls which need to be initialized on the server side and their scripts to be registered on the client.
The client side insert/update could be achieved only with external form like is shown into the following  example:
Also more about client side data binding limitations you could find here:  (Client side data-binding limitations)

I hope this helps.

All the best,
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question