• 在DataGrid中,如何录入数量及单价的时候自动算出金额


    23.在DataGrid中有3个模板列包含Textbox分别为 DG_ShuLiang (数量) DG_DanJian(单价) DG_JinE(金额)分别在5.6.7列,要求在录入数量及单价的时候自动算出金额即:数量*单价=金额还要求录入时限制为 数值型.我如何用客户端脚本实现这个功能?

    〖思归〗
    <asp:TemplateColumn HeaderText="数量">
    <ItemTemplate>
    <asp:TextBox id="ShuLiang" runat='server' Text='<%# DataBinder.Eval(Container.DataItem,"DG_ShuLiang")%>'
    onkeyup="javascript:DoCal()"
    />

    <asp:RegularExpressionValidator id="revS" runat="server" ControlToValidate="ShuLiang" ErrorMessage="must be integer" ValidationExpression="^d+$" />
    </ItemTemplate>
    </asp:TemplateColumn>

    <asp:TemplateColumn HeaderText="单价">
    <ItemTemplate>
    <asp:TextBox id="DanJian" runat='server' Text='<%# DataBinder.Eval(Container.DataItem,"DG_DanJian")%>'
    onkeyup="javascript:DoCal()"
    />

    <asp:RegularExpressionValidator id="revS2" runat="server" ControlToValidate="DanJian" ErrorMessage="must be numeric" ValidationExpression="^d+(.d*)?$" />

    </ItemTemplate>
    </asp:TemplateColumn>

    <asp:TemplateColumn HeaderText="金额">
    <ItemTemplate>
    <asp:TextBox id="JinE" runat='server' Text='<%# DataBinder.Eval(Container.DataItem,"DG_JinE")%>' />
    </ItemTemplate>
    </asp:TemplateColumn>

    <script language="javascript">
    function DoCal()
    {
    var e = event.srcElement;
    var row = e.parentNode.parentNode;
    var txts = row.all.tags("INPUT");
    if (!txts.length || txts.length < 3)
    return;

    var q = txts[txts.length-3].value;
    var p = txts[txts.length-2].value;

    if (isNaN(q) || isNaN(p))
    return;

    q = parseInt(q);
    p = parseFloat(p);

    txts[txts.length-1].value = (q * p).toFixed(2);
    }
    </script>

  • 相关阅读:
    substr函数
    Oracle 日期处理
    translate函数使用
    nvl函数
    random随机函数
    case语句
    列的拼接
    并行HASH JOIN小表广播问题
    WITH AS 优化逻辑读
    【hihoCoder挑战赛28 A】异或排序
  • 原文地址:https://www.cnblogs.com/nianshi/p/938761.html
Copyright © 2020-2023  润新知