在gridview中自动乘以两列 [英] Auto multiply two column in gridview
问题描述
HI,
我需要在gridview中计算两个textboxex的值,并在第二个文本框中输入值后立即在第三个文本框中使用javascript显示结果。
我的文本框字段包括:数量和价格
结果应以总计显示。
(总计)Value = Quantity * Rate。
我已经试过了,
CODE BEHIND:C#
protected void gvPOItms__RowCreated(Object sender,GridViewRowEventArgs e)
{
try
{
TextBox txt1 =(TextBox)e .Row.FindControl( txtQty);
TextBox txt2 =(TextBox)e.Row.FindControl(txtRate);
TextBox txt3 =(TextBox)e.Row.FindControl(txtValue);
txt1.Attributes [onKeyup] =javascript:return multiplication('+ txt1.ClientID +','+ txt2.ClientID +','+ txt3.ClientID + ');
txt2.Attributes [onKeyup] =javascript:return multiplication('+ txt1.ClientID +','+ txt2.ClientID +','+ txt3.ClientID +') ;
}
catch(Exception ex)
{
Response.Write(ex);
JAVASCRIPT:
< Script type =text / javascript>
函数乘法(tx1,txt2,txt3)
{
//乘法逻辑
var Qty = document.getElementById(txt1).value;
var Rate = document.getElementById(txt2).value;
document.getElementById(txt3).value = Qty * Rate;
}
< / script>
标记页面:
p>
但是,
有人可以告诉我什么是错的吗?
您应该将字符串更改为int(作为任何文本框的值返回字符串)在乘法之前:)
试试这个: -
txt1.Attributes [onKeyup] =javascript:return multiplication('+ Convert.ToInt32(txt1.Text)+ ','+ Convert.ToInt32(txt2.Text)+ , + Convert.ToInt32(txt3.ClientID)+);
txt2.Attributes [onKeyup] =javascript:return multiplication('+ Convert.ToInt32(txt1.Text)+','+ Convert.ToInt32(txt2.Text)+','' + Convert.ToInt32(txt3.ClientID)+');
在脚本中: -
< Script type =text / javascript>
函数乘法(Qty,Rate,txt3)
{
//您的乘法逻辑
document.getElementById(txt3).value = Qty * Rate;
}
< / script>
HI,
I need to calculate values of two textboxex in gridview and display the result in the third textbox using javascript as soon as the value entered in second textbox.
my textbox fields are: Quantity and Price The result should be displayed in Total.
that is, (Total)Value= Quantity * Rate.
I have tried this, CODE BEHIND:C#
protected void gvPOItms__RowCreated(Object sender, GridViewRowEventArgs e)
{
try
{
TextBox txt1 = (TextBox)e.Row.FindControl("txtQty");
TextBox txt2 = (TextBox)e.Row.FindControl("txtRate");
TextBox txt3 = (TextBox)e.Row.FindControl("txtValue");
txt1.Attributes["onKeyup"] = "javascript: return multiplication('" + txt1.ClientID + "','" + txt2.ClientID + "','" + txt3.ClientID + "')";
txt2.Attributes["onKeyup"] = "javascript: return multiplication('" + txt1.ClientID + "','" + txt2.ClientID + "','" + txt3.ClientID + "')";
}
catch (Exception ex)
{
Response.Write(ex);
}
}
JAVASCRIPT:
<Script type="text/javascript">
function multiplication(tx1,txt2,txt3)
{
//Your logic for multiplication
var Qty=document.getElementById(txt1).value;
var Rate=document.getElementById(txt2).value;
document.getElementById(txt3).value=Qty*Rate;
}
</script>
Markup Page:
But, i couldn't get the answer, its not throwing any error.
Can someone tell me what's wrong?
you should change string to int (as value of any textbox returns string) before multiplication :)
try this :-
txt1.Attributes["onKeyup"] = "javascript: return multiplication('" + Convert.ToInt32(txt1.Text) + "','" + Convert.ToInt32(txt2.Text) + "','" + Convert.ToInt32(txt3.ClientID) + "')";
txt2.Attributes["onKeyup"] = "javascript: return multiplication('" + Convert.ToInt32(txt1.Text) + "','" + Convert.ToInt32(txt2.Text) + "','" + Convert.ToInt32(txt3.ClientID) + "')";
In script :-
<Script type="text/javascript">
function multiplication(Qty,Rate,txt3)
{
//Your logic for multiplication
document.getElementById(txt3).value=Qty*Rate;
}
</script>
这篇关于在gridview中自动乘以两列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!