2013-04-15 69 views
0

我正在从SharePoint中检索数值。我想要做的是从列表中添加值。但是,我不确定如何在从SharePoint调用列时获取它。如何从SharePoint中获取数字列表的总和?

到目前为止,我有这样的:

//Column List from SharePoint which has a numeric value 

if (item["ows_Amount_x0020__x0028_LC_x0029_"] != null) 
{ 
    str.AppendLine("<td bgcolor='#FFFFFF';align='right';> " + Convert.ToDecimal(item["ows_Amount_x0020__x0028_LC_x0029_"]).ToString("N0") + "</td>"); 
} 

//Location where I want to put in the Sum 
str.AppendLine(" <tr style='color:#ffffff; font-weight:bold'><td bgcolor='#0096D6'>Forecast USD</td></tr>"); 
+0

这段代码 - 如果有的话 - 什么时候运行? – Brian

+0

@Brian它从SP列表中生成数据。 – Alphard

回答

1

假设你通过列表​​中每个项目的循环会是这个样子,因为对于像SPQuery SUM聚合函数的支持。

double total = 0; 
foreach(item in list){ 
    if(item["field"] == null) 
    continue; 

    total += item["field"]; 
    str.AppendLine("<td bgcolor='#FFFFFF';align='right';> " + Convert.ToDecimal(item["field"]).ToString("N0") + "</td>"); 
} 
str.AppendLine(" <tr style='color:#ffffff; font-weight:bold'><td bgcolor='#0096D6'>Forecast USD:" + total.toString() + "</td></tr>"); 
相关问题