日期:2014-05-20  浏览次数:20457 次

关于DataGrid的问题
在DataGrid控件中,在编辑模块中的Label该成TextBox,就是可以在显示的DataGrid中输数据,前面两个单元格输入的数据运算,怎样自动显示在第三个单元格中,求代码,具体写在那里,谢谢

------解决方案--------------------
帮顶 !
------解决方案--------------------
在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>

别人的代码你好好看看,看能否帮到你