用于交换列值的 Radgrid 中 RadNumeric 文本框的 KeyPress 事件 [英] KeyPress event for RadNumeric Textbox in Radgrid for exchanging coloumn values

查看:79
本文介绍了用于交换列值的 Radgrid 中 RadNumeric 文本框的 KeyPress 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用我的一种表单中的 RadGrid 用 C# 开发一个网站.下面是我用于 RadGrid 的 ASPX 代码:

I am developing a website in C# using a RadGrid in one of my forms. Below is my ASPX code for the RadGrid:

<telerik:RadGrid ID="GridViewAllocation" runat="server" Height="200px" Width="100%"
AutoGenerateColumns="False" GridLines="None"
OnItemDataBound="GridViewAllocation_ItemDataBound"
OnItemCommand="GridViewAllocation_ItemCommand">
    <MasterTableView>
        <Columns>
            <telerik:GridBoundColumn HeaderText="Amount O/S"   UniqueName="AMT" DataField="AMT">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn HeaderText="Allocate" UniqueName="Acc_Allocated"
                DataField="Acc_Allocated">
                <ItemTemplate>
                    <telerik:RadNumericTextBox ID="TextGirdAmntAlloc" runat="server" Value="0"
                    CssClass="gridTextEntry" OnTextChanged="TextGirdAmntAlloc_TextChanged"
                    AutoPostBack="true">
                        <NumberFormat GroupSeparator="" DecimalDigits="4" />
                    </telerik:RadNumericTextBox>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn UniqueName="ACC_SOURCE" DataField="ACC_SOURCE" Visible="false">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

在此网格中,当我单击或 KeyPress 或任何其他事件时,我想将 AMT 列的确切值传输到文本框 Acc_Allocated.传递值有一个条件:当 Acc_Source 值为 "3" 时,则转移该值,否则不转移.目前我正在通过 TextChanged 事件从服务器端检查.

In this grid I want to transfer the exact value of coloumn AMT to textbox Acc_Allocated when I click or KeyPress or with any other event. There is one condition for transfering the values: when Acc_Source value is "3" then transfer that value, otherwise do not. Currently I am checking from server side via the TextChanged event.

有没有其他方法可以做到这一点?

Is there any other way of doing this?

这是我的 TextChanged 事件:

Here is my TextChanged event:

   protected void TextGirdAmntAlloc_TextChanged(object sender, EventArgs e)
   {
       try
       {
         foreach (GridDataItem GrdItm in GridViewAllocation.MasterTableView.Items)
          {
            decimal GrdAccAllocAmnt = Convert.ToDecimal(((RadNumericTextBox)GrdItm.FindContro("TextGirdAmntAlloc")).Text);
            if (GrdItm["ACC_SOURCE"].Text == "3")
            {                   
                LblAmnt_Alloc.Text = GrdItm.Cells[4].Text;
                ((RadNumericTextBox)GrdItm.FindControl("TextGirdAmntAlloc")).Text = GrdItm.Cells[4].Text;                
            }
          }
        }
        catch { }
    }

推荐答案

请尝试使用以下代码片段.

Please try with below code snippet.

JS

 <script type="text/javascript">
        function ValueChanged(sender, args) {
            var grid = $find("<%= RadGrid1.ClientID %>");
            if (grid) {
                var MasterTable = grid.get_masterTableView();
                var Rows = MasterTable.get_dataItems();
                for (var i = 0; i < Rows.length; i++) {
                    var row = Rows[i];
                    var getCellText = row.get_cell("Name").innerHTML;
                    if (getCellText == "Name1") {
                        var TextGirdAmntAlloc = $telerik.findControl(row.get_element(), "TextGirdAmntAlloc");
                        TextGirdAmntAlloc.set_value(row.get_cell("ID").innerHTML);
                    } 
                }
            }
        }
    </script>

.aspx

 <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource"
        OnItemCreated="RadGrid1_ItemCreated">
        <MasterTableView DataKeyNames="ID">
            <Columns>
                <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn HeaderText="Allocate" UniqueName="Acc_Allocated" DataField="Acc_Allocated">
                    <ItemTemplate>
                        <telerik:RadNumericTextBox ID="TextGirdAmntAlloc" runat="server">
                            <ClientEvents OnValueChanged="ValueChanged" />
                        </telerik:RadNumericTextBox>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridEditCommandColumn>
                </telerik:GridEditCommandColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

这篇关于用于交换列值的 Radgrid 中 RadNumeric 文本框的 KeyPress 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆