0
votes

I have 1 RadNumericTextBox in my GridView in which i will allow user to enter some positive value(numbers only).

Code:

     <telerik:RadGrid ID="rgCalculation" datakeynames="ID" runat="server" OnItemDataBound="rgCalculation_ItemDataBound">
<MasterTableView AutoGenerateColumns="false" ClientDataKeyNames="ID">
     <telerik:GridTemplateColumn HeaderText="Amount" HeaderStyle-Width="20%">
                                        <ItemTemplate>
                                             <telerik:RadNumericTextBox ID="txtAmount" ClientEvents-OnValueChanged="OnClientValueChanged" MinValue="0" MaxValue="999999999" runat="server" AutoPostBack="true" OnTextChanged="txtAmount_TextChanged" />
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>

This is my Grid: enter image description here

Records like Interest and Worth are being loaded on ItemDataBound events from database.

Now when textbox1 value is changed i want to compare textbox1 value with textbox2 and if textbox1 value is smaller than texbox2 value then i want to display alert to user that textbox1 value cannot be less than texbox2 and also i want to display alert to user if user enter negative value in any of texbox1 or textbox2.

but here problem is that as both textbox would have same id then how would i get 2nd textbox value.

This is How i am getting first textbox value:

function OnClientValueChanged(sender, args) {
            alert(args.get_newValue())
        }

So how to get 2nd numeric textbox value??

1
How are you binding data to the second textbox? - MaCron
may seem as a side note, but you may want to take a look at the SpreadSheet component rather than a grid: demos.telerik.com/aspnet-ajax/spreadsheet/examples/overview/… - rdmptn

1 Answers

1
votes

You can get the cells/rows client-side according to their index or data key value: http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-cells-and-values-in-client-side-code

Here is the basic concept:

var grid = $find('<%= RadGrid1.ClientID %>');
var masterTable = grid.get_masterTableView();
var item = masterTable.get_dataItems()[3]; //replace 3 with the index you need (probably 1, judging from the screenshot)
var cell = masterTable.getCellByColumnUniqueName(item, "ShipCountry"); //replace ShipCountry with the unique name of your column

You may find the entire article useful in the future as well.