BatchEditCommand OldValues not set for GridTemplateColumn

1 Answer 48 Views
Grid NumericTextBox
Richard
Top achievements
Rank 4
Iron
Iron
Iron
Richard asked on 27 Nov 2024, 04:50 PM

Good afternoon,

I'm using a RadGrid with Batch Editing.  The grid is populated using OnNeedDataSource.

<telerik:RadGrid ID="RadGridEntries" runat="server" RenderMode="Lightweight" AllowSorting="True" CellSpacing="-1" GridLines="Horizontal"
    OnNeedDataSource="RadGridEntries_NeedDataSource" AllowAutomaticUpdates="false"
    AllowAutomaticInserts="false" AllowAutomaticDeletes="false" OnBatchEditCommand="RadGridEntries_BatchEditCommand"
    OnPreRender="RadGridEntries_PreRender">
    <ClientSettings>
        <Scrolling AllowScroll="true" UseStaticHeaders="true" SaveScrollPosition="true" />
    </ClientSettings>
    <MasterTableView Name="Authorities" AutoGenerateColumns="false" DataKeyNames="Index_id"
        CommandItemDisplay="Top" EditMode="Batch" BatchEditingSettings-OpenEditingEvent="DblClick" HeaderStyle-HorizontalAlign="Center">
        <CommandItemSettings ShowRefreshButton="false" />
        <BatchEditingSettings EditType="Row" HighlightDeletedRows="true" />
        <Columns>
            <telerik:GridBoundColumn DataField="Index_id" UniqueName="Index_id" ReadOnly="true" Visible="false" Exportable="false" />
            <telerik:GridBoundColumn DataField="Authority" SortExpression="Authority" UniqueName="Authority"
                HeaderText="Authority" MaxLength="2">
				<ColumnValidationSettings EnableRequiredFieldValidation="true">
					<RequiredFieldValidator ForeColor="Red" Text="*Authority is required" Display="Dynamic">
					</RequiredFieldValidator>
				</ColumnValidationSettings>
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Short_description" SortExpression="Short_description" UniqueName="Short_description"
                MaxLength="30" HeaderText="Short Description" ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="150px">
				<ColumnValidationSettings EnableRequiredFieldValidation="true">
					<RequiredFieldValidator ForeColor="Red" Text="*Short Description is required" Display="Dynamic">
					</RequiredFieldValidator>
				</ColumnValidationSettings>
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Long_description" SortExpression="Long_description" UniqueName="Long_description"
                MaxLength="100" HeaderText="Long Description" ItemStyle-HorizontalAlign="Left" HeaderStyle-Width="200px" />
            <telerik:GridTemplateColumn DataField="Percentage" SortExpression="Percentage" UniqueName="Percentage" HeaderText="Percentage">
                <ItemTemplate>
                    <%#DataBinder.Eval(Container.DataItem, "Percentage","{0} %")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <span>
                        <telerik:RadNumericTextBox RenderMode="Lightweight" Width="75px" runat="server" ID="txtPercentage"
                            MaxValue="100" MinValue="-100">
                            <NumberFormat DecimalDigits="3" NegativePattern="-n %" PositivePattern="n %" />
                        </telerik:RadNumericTextBox>
                        <span style="color: Red">
                            <asp:RequiredFieldValidator ID="rvPercentage"
                                ControlToValidate="txtPercentage" ErrorMessage="*Percentage is required" runat="server" Display="Dynamic">
                            </asp:RequiredFieldValidator>
                        </span>
                    </span>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridCheckBoxColumn DataField="IsPriceList" DataType="System.Boolean" SortExpression="IsPriceList"
                StringFalseValue="0" StringTrueValue="1" HeaderText="Price List" />
            <telerik:GridBoundColumn DataField="Date_amended" SortExpression="Date_amended" HeaderText="Date Amended" ReadOnly="true" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

In RadGridEntries_BatchEditCommand I'm capturing the old and new values:

Hashtable newValues = command.NewValues;
Hashtable oldValues = command.OldValues;

But the Percentage template column is missing from OldValues:

The Percentage column is stored as a decimal(6,3).  I'm trying to display the value with the 3 d.p and a % sign.  It's not stored as a percentage i.e. if the value is stored as 10.505 then it is displayed as 10.505 - I'm not storing it divided by 100.

I'm using the Command Item buttons to Save and Insert.

What can I do to make sure that the Percentage Old Value is stored so that I can compare it to the New Value?

Kind regards,

Richard

Richard
Top achievements
Rank 4
Iron
Iron
Iron
commented on 29 Nov 2024, 04:51 PM | edited

1 Answer, 1 is accepted

Sort by
0
Accepted
Richard
Top achievements
Rank 4
Iron
Iron
Iron
answered on 29 Nov 2024, 04:52 PM

Afternoon,

I managed to find the answer I needed in this article:

Telerik Web Forms Grid Data Editing Edit Mode Batch Editing Server-side API - Telerik UI for ASP.NET AJAX

The old values for a TemplateColumn are available in the OldValues hashtable only if the DataField is added to the DataKeyNames collection.

This addition allowed it to work:

<MasterTableView Name="Authorities" AutoGenerateColumns="false" DataKeyNames="Index_id, Percentage"

Kind regards,

Richard

Tags
Grid NumericTextBox
Asked by
Richard
Top achievements
Rank 4
Iron
Iron
Iron
Answers by
Richard
Top achievements
Rank 4
Iron
Iron
Iron
Share this question
or