我有5列数据:
- ID
- Name
- Account Number
- Branch
- Amount
该表包含5行。
我怎么能够把“总金额”显示在“Label Control”中的总和?
我有5列数据:
该表包含5行。
我怎么能够把“总金额”显示在“Label Control”中的总和?
计算可数据使用的一栏总和:。
相关的MSDN条款的使用实例:
DataTable table = dataSet.Tables["YourTableName"];
// Declare an object variable.
object sumObject;
sumObject = table.Compute("Sum(Amount)", string.Empty);
a. 显示结果,按原样显示:
lblTotalAmount.Text = sumObject.ToString();
this.LabelControl.Text = datatable.AsEnumerable()
.Sum(x => x.Field<int>("Amount"))
.ToString();
如果你想要过滤结果:
this.LabelControl.Text = datatable.AsEnumerable()
.Where(y => y.Field<string>("SomeCol") != "foo")
.Sum(x => x.Field<int>("MyColumn") )
.ToString();
你可以这样做。
DataRow[] dr = dtbl.Select("SUM(Amount)");
txtTotalAmount.Text = Convert.ToString(dr[0]);
如果是,你有《反歧视法》。 可上网
int sum = 0;
foreach(DataRow dr in dataTable.Rows)
{
sum += Convert.ToInt32(dr["Amount"]);
}
如果你想询问数据库表,你可以使用。
Select Sum(Amount) From DataTable
public decimal Total()
{
decimal decTotal=(datagridview1.DataSource as DataTable).Compute("Sum(FieldName)","");
return decTotal;
}
图表中各栏的概要,100%
lbl_TotaAmt.Text = MyDataTable.Compute("Sum(BalAmt)", "").ToString();
如果你想要具备任何条件,就象这样使用。
lbl_TotaAmt.Text = MyDataTable.Compute("Sum(BalAmt)", "srno=1 or srno in(1,2)").ToString();
引言
int sum = 0;
foreach (DataRow dr in dt.Rows)
{
dynamic value = dr[index].ToString();
if (!string.IsNullOrEmpty(value))
{
sum += Convert.ToInt32(value);
}
}
我认为这一解决办法
using System.Linq;
(datagridview1.DataSource as DataTable).AsEnumerable().Sum(c => c.Field<double>("valor"))
如果你在您的档案中再次想这样做的话,你可以照此写(包括LMBDA的表述):
<td><b>£@Model.Sum(i => i.Amount)</b></td>
你们可以去除html的标签,我只是让它们去尝试和帮助。
In my webpages I have references to js and images as such: "../../Content/Images/"Filename" In my code if I reference a file as above, it doesnt work so i have to write: "c:/miscfiles/"filename" 1-...
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
I m looking for best practices here. Sorry. I know it s subjective, but there are a lot of smart people here, so there ought to be some "very good" ways of doing this. I have a custom object called ...
I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...
i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...
For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?
I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!