将SPListItem添加到SPListItemCollection

时间:2015-11-23 11:47:47

标签: c# asp.net sharepoint-2013

我有以下代码从sharepoint站点加载列表。

ALl运行良好,将SPList项目释放到SPListItemCollection。

 private void Data_load()
        {
            DataTable dt = new DataTable();


            string currentName = SPContext.Current.Web.CurrentUser.Name;
            SPQuery query = new SPQuery();
            query.Query = "<Where><Eq><FieldRef Name='Editor'/><Value Type='Person or Group'>" + currentName + "</Value></Eq></Where>";

            using (SPSite site = new SPSite("http://spdev-6/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList lists = web.GetList("Lists/Advertisements");

                    SPListItemCollection items = lists.GetItems(query);

                    if (items.Count > 0)
                    {
                        DataRow dr=null;
                        SPListItemCollection ITEM = null;
                        foreach(SPListItem item in items)
                        {
                            string A = item["Approval Status"].ToString();
                            if(A== "2")
                            {
                                ITEM.Add(item);

                            }


                        }
                        if(dt.Rows.Count==0)
                            lbldata.Text = "No data to show";

                      //  dt = items.GetDataTable();


                    }
                    else
                        lbldata.Text = "No data to show";



                    GridViewD.DataSource = dt;
                    GridViewD.DataBind();
                    HttpContext.Current.Session["Advertisement"] = dt;


                }
            }

        }

现在在if(A ==“2”){ITEM.Add(item); }

我想将SPListItem添加到SPListItemCollection。请帮忙。

0 个答案:

没有答案