[英]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.