如何使用网格视图值计算总价 [英] how to calculate total price using grid view values

查看:88
本文介绍了如何使用网格视图值计算总价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以提供代码以计算总价格偏离网格视图价格,每一行的数量...请帮助我....

我的编码只计算网格的最后一行...

Can Anyone Give Code for calculate total price depands on gridview price,quantity in each row...ple help me....

my coding calculate only last row of grid...

pro_id    pro_name    quantity     price Edit Update Delete

 55       flowers         2         300
 60     party flower      1         680



              Shopping Cart Details

                                 TotalPrice : 680  //  Error


DeliveryPlace :   chennai
DeliveryCharge :   250
Tax (in %) :        10
Shipping :
NetPrice :







错误编码:








Error Coding:


public void totalprice()
   {
       float pricee;
       int quantityy;
       foreach (GridViewRow row in GridView1.Rows)
       {
           int pro_id = Convert.ToInt32(GridView1.DataKeys[row.RowIndex][0]);
           pricee = dal.getprice(pro_id);
           quantityy = dal.getquantity(pro_id);
           float totalprice = quantityy * pricee;
           lbltprice.Text = totalprice.ToString();
       }
   }

推荐答案

尝试以下代码:

try this code:

public void totalprice()
   {
       float pricee;
       int quantityy;
      float totalprice;
       foreach (GridViewRow row in GridView1.Rows)
       {
           int pro_id = Convert.ToInt32(GridView1.DataKeys[row.RowIndex][0]);
           pricee = dal.getprice(pro_id);
           quantityy = dal.getquantity(pro_id);
           totalprice += quantityy * pricee;
       }
      lbltprice.Text = totalprice.ToString();
   }



希望对您有帮助!

不要忘记投票:)



hope it helps!

don''t forget to vote :)


// this is a javascript code used to retrieve gridview row value
function Read_Data()
{
    var str=0;
    // here grid_list is the id of your asp.net gridview
    // grid_list.ClientID gives asp.net server executed id of the gridview
    // inside the for loop cells[3] which denote 3 column from the gridview
    // str is a variable which will sum up all your row values on the column
    var Grid_Table = document.getElementById('<%=grid_list.ClientID%>');
    for(var row=1; row<Grid_Table.rows.length; row++)
    {
                    if(document.all)
                        str=str+Number(Grid_Table.rows[row].cells[3].innerText);

                    else
                        str=str+Number(Grid_Table.rows[row].cells[3].textContent);

    }
    alert(str);
    return false;
}


这篇关于如何使用网格视图值计算总价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆