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

Get/Set RadNumericTextbox in RadGrid Edit Mode using Javascript?

1 Answer 437 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brock
Top achievements
Rank 1
Brock asked on 15 Apr 2011, 03:54 PM
so far, I've figured out how to get and set values of a RadNumericTextBox within a RadGrid during edit mode using the following Javascript.

                //GET QUANTITY
                var quantityId = $telerik.$("[id$='Quantity']").attr('id'); //get Client ID of RadNumericTextbox with Id 'Quantity'
                var quantityControl = $find(quantityId);                    //get control
                var quantityValue = quantityControl.get_value();             //get value stored in control


                //SET QUANTITY
                quantityControl .set_value(5);                //set value in control


My problem is that in edit mode, this code only works for RadNumericTextBoxes in the very first row. It simply fails for all other rows. I believe it's because the $telerik.$("[id$='Quantity']").attr('id'); isn't able to find the client id for the other rows correctly.

I've look at several examples here and in forums and I'm unable to find a solution.

Also, speed is a primary concern. When the user changes the value for one textbox in the row, I use these gets and sets to perform instantaneous calculations on values contained within other textboxes within that same row.

Thanks for any help you can provide!

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Apr 2011, 10:35 AM
Hello Brock,

Try the following approach to get the RadNumericTextBox and its value from client side when the grid is in edit mode. Attach 'OnLoad' client event to RadNumericTextBox and save the RadNumericTextBox id globally like below.

ASPX:
<telerik:RadGrid ID="RadGrid1" >
    <MasterTableView>
        <Columns>
         <telerik:GridTemplateColumn>
                <EditItemTemplate>
                    <telerik:RadNumericTextBox runat="server" ID="RadNumericTextBox1">
                        <ClientEvents OnLoad="NumericTextBoxOnLoad" />
                    </telerik:RadNumericTextBox>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <ClientEvents OnCommand="OnCommand" />
    </ClientSettings>
</telerik:RadGrid>

Java Script:
<script type="text/javascript">
    var numericTextBox;
    function NumericTextBoxOnLoad(sender, args) {
        numericTextBox = sender;
    }
    function OnCommand(sender, args) {
      if (args.get_commandName() == "Update") {
           var value = numericTextBox.get_value();
        }
    }
</script>

Thanks,
Princy.
Tags
Grid
Asked by
Brock
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or