如何从gridview检索价格和数量,以及如何在asp.net中计算totalprice [英] how to retrive price and quantity from gridview and how to calculate totalprice in asp.net
问题描述
任何人都可以帮忙吗?
如何从gridview检索价格和数量并将其显示在页脚中&如何在asp.net中计算totalprice
Can anyone help?
how to retrive price and quantity from gridview and show it in footer also & how to calculate totalprice in asp.net
protected void totalprice()
{
int quantity = int.Parse("txtquantity");
float price =float.Parse("price");
float totalprice = float.Parse("totalPrice");
totalprice=quantity * price;
}
这是正确的吗?
is thi correct?
推荐答案
function calculateGridTotal() { // call this on body load
var tmpgvRenewal = document.getElementById("gvRenewal"); // this is the gridis
var Price = 0.0;
var Quantity = 0.0;
var TotalPrice = 0.0;
var arrstr = tmpgvRenewal.id + "_ctl";
for (var i = 2; i <= tmpgvRenewal.childNodes[0].childNodes.length - 1; i++) { //search for all row of grid view and calculate whatever you want
if (parseInt(i) < 10) {
var c = "0" + i;
}
else {
var c = i;
}
var lblQuantity = document.getElementById(arrstr + c + "_lblQuantity").innerHTML;
var lblPrice= document.getElementById(arrstr + c + "_lblPrice").innerHTML;
lblQuantity= lblQuantity.replace(/,/g, ''); // if that value is like(100,000,00)
lblPrice = lblPrice.replace(/,/g, '');
if (lblQuantity != "")
Quantity = Quantity + parseFloat(lblQuantity);
if (lblPrice!= "")
Price = Price + parseFloat(lblPrice);
}
TotalPrice = Price * Quantity;
tmpgvRenewal.rows[tmpgvRenewal.rows.length - 1].cells[2].innerHTML = Quantity; // assign it to footer row of grid(make footer row visible = true) (Total Quantity)
tmpgvRenewal.rows[tmpgvRenewal.rows.length - 1].cells[3].innerHTML = Price;
tmpgvRenewal.rows[tmpgvRenewal.rows.length - 1].cells[4].innerHTML = TotalPrice;
}
试试这个java脚本.计算网格元素和插入页脚的总计.
try this java script. to calculate total of grid element and assin into footer.
使AutoGenerateSelectButton = true,
在gridview的rowcommand上
make AutoGenerateSelectButton=true,
on rowcommand of gridview
protected void fect_taskid(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
string pr = row.Cells[1].Text;//1 will be the index of Price
string qt=row.Cells[2].Text;
float lbltotalprice=float.Parse(int.Parse(qt)*float.Parse(pr))
}
您可以这样做.
you can do like this .
Protected void Totalprice()
{
foreach(GridViewRow gvRow in GridViewName.Rows)
{
int Quantity = Convert.ToInt32(((TextBox)gvRow.FindControl("txtquantity")).Text)
int Price = float.tryParse(((Label)gvRow.FindControl("lblPrice")).Text)
float TotalPrice = Quantity * Price;
// find here footer Control of gridview and set the value.
// first you have to make sure ShowFooterRow is true
lblFooterTotalPrice = (Label)gvrow.FindControl("lblfootertotalPrice");
lblFooterTotalPrice.Text = TotalPrice;
}
}
这篇关于如何从gridview检索价格和数量,以及如何在asp.net中计算totalprice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!