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

Batch Update Gets Old Value from RadNumericTextBox

3 Answers 229 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kencox
Top achievements
Rank 1
kencox asked on 15 Mar 2011, 08:09 PM
I'm following the examples to perform a batch update in a radgrid.

However, the HashTable contains the old value for the RadNumericTextBox. I want whatever the user has just typed in. I have some client-side script that format the numbers.

How can I get the most recent value that the user typed in as the qty value?

Here's the template column markup:

<telerik:GridTemplateColumn DataField="Qty" DataType="System.Decimal" HeaderText="Qty"
    SortExpression="Qty" UniqueName="Qty">
    <EditItemTemplate>
        <telerik:RadNumericTextBox Width="40px" MinValue="0" MaxValue="9999999.99" Type="Number"
            ID="QtyTextBox" Text='<%# Bind("Qty") %>' InvalidStyleDuration="1000" NumberFormat-DecimalDigits="2"
            runat="server" MaxLength="20">
            <ClientEvents OnLoad="RemoveZeros" OnBlur="RemoveZeros" OnValueChanged="RemoveZeros" />
        </telerik:RadNumericTextBox>
        <asp:RangeValidator ID="rngQty" runat="server" ControlToValidate="QtyTextBox" ErrorMessage="<br />Must be a number"
            Display="Dynamic" MinimumValue="0" MaximumValue="999999999" Type="Double"></asp:RangeValidator>
        <asp:RequiredFieldValidator ID="reqQty" ControlToValidate="QtyTextBox" runat="server"
            Display="Dynamic" ErrorMessage="<br />A quantity is required."></asp:RequiredFieldValidator>
    </EditItemTemplate>
    <ItemTemplate>
        <asp:Label ID="QtyLabel" runat="server" Text='<%# FormatDecimalWithoutUnusedDecimals( Eval("Qty")) %>'></asp:Label>
    </ItemTemplate>
    <ItemStyle Width="55px" />
    <HeaderStyle Width="55px" />
    <FooterStyle HorizontalAlign="Right" />
    <FooterTemplate>
    </FooterTemplate>
</telerik:GridTemplateColumn>

Here's the code:

Protected Sub RadGrid1_ItemCommand(ByVal source As Object, _
              ByVal e As Telerik.Web.UI.GridCommandEventArgs) _
              Handles RadGrid1.ItemCommand
    Dim newValues As New Hashtable
    If e.CommandName = "UpdateAll" Then
        UpdateShipment(Nothing, Nothing)
        For Each editedItem As GridEditableItem In RadGrid1.EditItems
            e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem)
            Dim QtyTextBox As RadNumericTextBox
            QtyTextBox = CType(editedItem("Qty").FindControl("QtyTextBox"), RadNumericTextBox)
            UpdateRowValue(newValues)
        Next
        RadGrid1.EditIndexes.Clear()
        RadGrid1.Rebind()
    End If
End Sub

Here's the Javascript:

function RemoveZeros(sender, args) {
    var tbValue = sender._textBoxElement.value;
    if (tbValue.indexOf(".00") != -1)
        sender._textBoxElement.value = tbValue.substr(0, tbValue.indexOf(".00"));
}

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Mar 2011, 06:20 AM
Hello Ken,

If you are using Radgrid EditMode as EditForms or PopUp, then to access edit form for an item use its EditFormItem property.

VB.NET:
For Each editedItem As GridEditFormItem In RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem)
.   .   .   .   .
Next


Thanks,
Princy.
0
kencox
Top achievements
Rank 1
answered on 16 Mar 2011, 07:11 AM
Hi Princy,

Thanks for your answer but I'm using InPlace edit mode so that's not the solution.

Ken
0
Veli
Telerik team
answered on 19 Mar 2011, 08:04 AM
Hi Ken,

The approach you have taken is correct. I have verified your scenario by putting the same code you posted to a test page. The newly entered value is extracted OK in the ItemCommand event handler as you have specified. The problem does not seem to be in way RadGrid extract your values. This leaves two very likely causes:

1. Improper RadGrid control life cycle. The issue you are getting may be caused by RadGrid not getting properly initialized on postback. Make sure RadGrid is not rebound before its ItemCommand event fires. Rebinding the grid would case its edit items to be recreated with their original edited values.

2. The javascript you are using (the RemoveZeroes function) is breaking the control behavior by modifying fields or using non-public API. To test this case - remove your javascript event handlers from RadNumericTextBox and see if the values are extracted properly. If this is the case, post your javascript so that we can exam it.

Veli
the Telerik team
Tags
Grid
Asked by
kencox
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
kencox
Top achievements
Rank 1
Veli
Telerik team
Share this question
or