0

我有一个转发器控件和绑定列表内容。但我还需要从另一个列表中获取数据并绑定到该列。如下所示,我需要为 Linq 查询中的每个列表项调用 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());
                      }

任何人都可以建议我是否需要为每个项目调用方法以便附加到中继器中。

4

0 回答 0