i have a datagridview which are used to display a transaction record. And one of the columns in datagridview is \"amount\"
girdview codeenter code here
use table.Compute function
private void ComputeBySalesSalesID(DataSet dataSet)
{
// Presumes a DataTable named "Orders" that has a column named "Total."
DataTable table;
table = dataSet.Tables["Orders"];
// Declare an object variable.
object sumObject;
sumObject = table.Compute("Sum(Total)", "EmpID = 5");
//Find label
GridViewRow footer = dgOpenBal.FooterRow;
var lblTotal = (Label)footer.FindControl("lblTotal");
lblTotal.Text = sumObject.ToString();
}
Another approach use stored procedure to get calculated amount from Sproc
private void ComputeBySalesSalesID(DataSet ds)
{
if (ds.Tables[0].Rows.Count > 0)
{
DataRow drSum = ds.Tables[0].Rows[0];
GridViewRow footer = dgOpenBal.FooterRow;
var lblTotal = (Label)footer.FindControl("lblTotal");
lblTotal.Text = drSum["sum"].ToString();
}
}