如何在Linq查询中调用方法

时间:2013-10-05 02:57:52

标签: c#-4.0 sharepoint sharepoint-2010

我有一个转发器控件和绑定列表内容。但我还需要从另一个列表中获取数据并绑定到此列。 如下所示,我需要为Linq查询中的每个List Item调用getvalue方法。当我尝试如下所示时,itemscount的值始终为null

    public void DeptInfo() 
                    {
                    SPList olist = web.Lists["Administration"];
                    SPListItemCollection itemscoll = olist.GetItems();
                    string itemscount = string.Empty;
                    if (itemscoll.Count > 0)
                    {
                        var listcontents = (from item in itemscoll.OfType<SPListItem>()
                                   select new
                                   {
                                       itemscount = getvalue(web, item),
                                       DepartmentName = item["Title"] +  itemscount          // DepartmentName is the column in repeater                                    
                                   }); 
                        if (listcontents.ToList().Count != 0)
                        {
                            Repeater.DataSource = listcontents.ToList();
                            Repeater.DataBind();
                        }
                    }
                    }

                      public string getvalue(SPWeb web, SPListItem item)
                      {
                                    SPListItemCollection spItemCollection = null;
                                    SPList olist = web.Lists["DepartmentList"];
                                    SPQuery spQuery = new SPQuery();
                                    spQuery.Query = "<Where><Eq><FieldRef Name='Division' /><Value Type='LookupMulti'>" + Convert.ToString(item["Title"]) + "</Value></Eq></Where>";
                                    spItemCollection = olist.GetItems(spQuery);
                                    return (spItemCollection.Count.ToString());
                      }

如果需要对每个项目调用方法进行任何更改以便附加到转发器中,是否有人可以建议我。

0 个答案:

没有答案