<itemtemplate>
<asp:textbox id=”shuliang” runat=server text=<%# databinder.eval(container.dataitem,”dg_shuliang”)%>
onkeyup=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=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>
資料來源:http://bbs.hidotnet.com/13796/showpost.aspx