如何在gridview中显示总数 [英] How to show the total in gridview

查看:108
本文介绍了如何在gridview中显示总数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在gridview中显示总共两行,请帮我执行此操作,真的我不知道如何编写代码,我的代码是什么,



I am trying to show the total of two rows in gridview , please help me to perform this , really I don't know how to code this, what I have the code is,

protected void btnAdd_Click(object sender, EventArgs e)
{
    objDetLst.Clear();
    objDet = new SalesDetails();
    objDet.TrID = 0;
    objDet.ItemCode = hidItemCode.Text;
    objDet.Quantity = Convert.ToDecimal(txtQuantity.Text);
    objDet.Price = 0;
    objDetLst.Add(objDet);
    CreateList();
    LoadGridView();
    txtItemCode.Text = "";
    txtQuantity.Text = "";
    decimal  total = 0;
    total = Convert.ToDecimal(objDet.Quantity) * Convert.ToDecimal(objDet.Price);
    total = grvList.Rows[0].Cells[4].Text ;




}





当我按下添加按钮应该添加商品代码,数量,价格和总数。

我怎么做。请帮帮我。



when I press add button should add the item code, qty , price and total.
how I can do it. please help me.

推荐答案

试试这个,



找到两个标签(即数量和价格) )从您的gridview上的行数据绑定并乘以两个值并将其绑定在总列中,

Try this,

find the two labels(i.e, quantity and price) from your gridview on row data bound and multiply two values and bind it in total column,
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    
        label lqty=(label)e.Row.findcontrol("Quantity_labelid_from Grid");
        label lprice=(label)e.Row.findcontrol("Price_id_from Grid");
        
        float total=float.parse(lqty.text)*float.parse(lprice.text);
        
        label ltot=(label)e.Row.findcontrol("Total_columnId");
        ltot.text=total.tostring();   
    }
}









已添加 pre 标签。

[/编辑]


protected void grvList_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    
                TextBox tqty = (TextBox)e.Row.FindControl("txtQuantity");
                TextBox tprice = (TextBox)e.Row.FindControl("txtPrice");

                float total = float.Parse(tqty.Text) * float.Parse(tprice.Text);

                TextBox ttot = (TextBox)e.Row.FindControl("txttotal");
                ttot.Text = total.ToString(); 
    }
}


这篇关于如何在gridview中显示总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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