簡體   English   中英

在不使用頁腳行的情況下,如何計算asp.net gridview中的列總和?

[英]how to calculate column sum in asp .net gridview without using footer row?

我有一列顯示成本的GridView 我想將這筆費用相加並顯示為帳單金額。 adding/deleting行時,應updated開票金額。

我正在使用asp .net c#

您應該在rowDataBound事件中執行此操作,在rowDataBound事件中,您將能夠訪問當前綁定的行中的每個cell ,並將值求和成一個variable

另一種方法是直接從Database計算值

protected void txtUnitPrice_TextChanged(object sender, EventArgs e)
{
    try
    {
        DataSet dset3 = new DataSet();
        GridViewRow currentRow = (GridViewRow)((TextBox)sender).Parent.Parent;
        TextBox qty = (TextBox)currentRow.FindControl("txtqty");
        TextBox qty1 = (TextBox)currentRow.FindControl("txtUnitPrice");
        string a = qty.Text;
        TextBox totalprice = (TextBox)currentRow.FindControl("txttotal");
        totalprice.Text = (Double.Parse(qty1.Text) * Double.Parse(qty.Text)).ToString();

    }
    catch (Exception ex)
    {

    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM