如何在gridview中多显示两个文本框,并在同一gridview中的第三个文本框中显示结果 [英] How to mutiply two textbox inside a gridview and show the result in the third textbox in the same gridview
本文介绍了如何在gridview中多显示两个文本框,并在同一gridview中的第三个文本框中显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我想要将两个文本框值相乘并希望将结果存储在gridview内的第三个文本框中的示例代码我的问题是我需要一个文本框而不是我从标签获得的硬编码值(奖品)
这是我的aspx页面
this is the sample code i want to multiply two textbox values and want to store the result in the third textbox inside a gridview my problem is that i need a textbox instead of hardcoded values that i m getting from label(prize)
this is my aspx page
$(function () {
$("[id*=txtQuantity]").val("0");
});
$("[id*=txtQuantity]").live("change", function () {
if (isNaN(parseInt($(this).val()))) {
$(this).val('0');
} else {
$(this).val(parseInt($(this).val()).toString());
}
});
$("[id*=txtQuantity]").live("keyup", function () {
if (!jQuery.trim($(this).val()) == '') {
if (!isNaN(parseFloat($(this).val()))) {
var row = $(this).closest("tr");
$("[id*=lblTotal]", row).html(parseFloat($(".price", row).html()) * parseFloat($(this).val()));
}
} else {
$(this).val('');
}
var grandTotal = 0;
$("[id*=lblTotal]").each(function () {
grandTotal = grandTotal + parseFloat($(this).html());
});
$("[id*=lblGrandTotal]").html(grandTotal.toString());
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Item" HeaderText="Item" />
<asp:BoundField DataField="Price" HeaderText="Price" ItemStyle-CssClass="price" />
<asp:TemplateField HeaderText = "Quantity">
<ItemTemplate>
<asp:TextBox ID="txtQuantity" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "Total">
<ItemTemplate>
<asp:Label ID="lblTotal" runat="server" Text="0"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Grand Total:
<asp:Label ID="lblGrandTotal" runat="server" Text="0"></asp:Label>
</form>
</body>
</html>
我的cs页面:
my cs page:
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Item"), new DataColumn("Price") });
dt.Rows.Add("Shirt", 200);
dt.Rows.Add("Football", 30);
dt.Rows.Add("Bat", 22.5);
GridView1.DataSource = dt;
GridView1.DataBind();
}
推荐答案
(function(){
(function () {
([id * = txtQuantity])。val(0);
});
("[id*=txtQuantity]").val("0"); });
([id * = txtQuantity])。live(change,function( ){
if(isNaN(parseInt(
("[id*=txtQuantity]").live("change", function () { if (isNaN(parseInt(
这篇关于如何在gridview中多显示两个文本框,并在同一gridview中的第三个文本框中显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文