2015-12-30 51 views
0

我在我的GridView中有1个RadNumericTextBox,我将允许用户输入一些正值(仅限数字)。如何获取客户端GridView内的第二个数字文本框的值?

代码:

 <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> 

这是我的网格: enter image description here

的记录,像利益值得被装上的ItemDataBound从数据库事件。

现在,当TextBox1中值改变,我想TextBox1的价值与TextBox2中,如果TextBox1的值比texbox2值小的话,我想显示警告用户该TextBox1的值不能小于texbox2,也是我想要显示警报比较如果用户在任何texbox1或textbox2中输入负值,则为用户。

但这里的问题是,因为两个文本框会有相同的ID,那么我将如何获得第二个文本框的值。

这就是我如何得到第一个文本框的值:

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

那么如何让第二个数字文本框的值?

+0

你如何将数据绑定到第二个文本框? – MaCron

+0

可能看起来像一个旁注,但您可能想看看SpreadSheet组件而不是网格:http://demos.telerik.com/aspnet-ajax/spreadsheet/examples/overview/defaultcs.aspx – rdmptn

回答

1

您可以根据自己的索引或数据键值得到的细胞/行客户端:http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-cells-and-values-in-client-side-code

这里的基本概念:

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 

您可能会发现有用的全部文章未来也是如此。

相关问题