我有一个名为gvSector的网格视图。 此表的字段如下:gridview选择的值
Sector Name Amount Invested
Finance 300000
Properties 100000
... ...
条件:如果投资于特定行业的量超过30% 我的标签lbSector
会显示该部门的名称。
我在.cs文件中的代码如下。
double TotalInvestments = 0.0;
for (int i = 0; i < gvSector.Rows.Count; i++)
{
if (gvSector.Rows.Count > 0)
{
double SAmt = Convert.ToDouble(gvSector.Rows[i].Cells[1].Text);
TotalInvestments += SAmt;
double PercentSAmt = (SAmt/TotalInvestments) * 100;
if (PercentSAmt > 25.0)
{
//I've no idea what to put here. It is supposed to show the sector(s) that is more than 25% from the gridview.
}
}
}
您应该在dbms中执行计算(如以''getTopSectors'作为SP,它将%值作为参数)。 – 2012-02-02 14:43:25
我不能这样做吗? – user1125911 2012-02-02 14:44:14
是的,你可以,但你不需要通常这样做。目前还不清楚你想达到的目标。是否必须显示所有记录,或只有部门> = 30%? – 2012-02-02 14:45:43