晨风

-------------------- 业精于勤,荒于嬉;行成于思,毁于随

导航

JqueryGridview模板列求和

Posted on 2011-12-28 22:58  shenyixin  阅读(1356)  评论(0编辑  收藏  举报

gridview中模板列TextBox求和赋值给一个TextBox(txt总维修金额)

html:

<Chsoft:SmartGridView ID="gv设备_外协维修合同明细" runat="server" Width="100%" IsShowIndexColumn="true" DataKeyNames="外协维修合同明细ID" AllowPaging="false"
IsShowExcelLinkButton
="false" IsSinglePageDataMode="False"
UnExportColumns
="操作">
<Columns>
<asp:TemplateField HeaderText="材料费用">
<ItemStyle HorizontalAlign="Right" Width="80px" />
<ItemTemplate>
<Chsoft:SmartNumericTextBox ID="txt材料费用" DecimalSeparator="Dot" IsAllowDecimals="true"
Width
="60px" runat="server" MaxLength="10" CssClass="class材料费用" IsAllowNegative="false"></Chsoft:SmartNumericTextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="人工费用">
<ItemStyle HorizontalAlign="Right" Width="80px" />
<ItemTemplate>
<Chsoft:SmartNumericTextBox ID="txt人工费用" DecimalSeparator="Dot" IsAllowDecimals="true"
Width
="60px" runat="server" MaxLength="10" CssClass="class人工费用" IsAllowNegative="false"></Chsoft:SmartNumericTextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</Chsoft:SmartGridView>

JsCode:

<script language="javascript" type="text/javascript">
Sys.Application.add_load(function () {
var classDiscount = $("#<%=gv设备_外协维修合同明细.ClientID %>").contents().find(".class材料费用");
classDiscount.keyup(function () {
ChangeText($(this));
});
var classDiscount = $("#<%=gv设备_外协维修合同明细.ClientID %>").contents().find(".class人工费用");
classDiscount.keyup(function () {
ChangeText($(this));
});
function ChangeText(target) {
var txt总维修金额 = $("#<%=txt总维修金额.ClientID %>");
if (target.val() != "0") {
var con = $("#<% =gv设备_外协维修合同明细.ClientID %> :text");
var count = 0;
for (var i = 0; i < con.length; i++) {
count = Number(count) + Number(con[i].value);
}
txt总维修金额.val(count);
}
}
});
</script>