如何从 UserControl.ascx.cs SharePoint 访问解决方案列表项

How To Access Solution List Item from UserControl.ascx.cs SharePoint

这是我的 UserControl.ascx.cs 部分 class

namespace SP.ExampleProject.CONTROLTEMPLATES
 {
    public partial class ExampleProjectUserControl : UserControl
  {

    public SPUser currentSuperUser = SPContext.Current.Web.CurrentUser;

    protected void Page_Load(object sender, EventArgs e)
    {
        int id = this.ListItem.ID; // Can't use ListItem
        SPWeb web = Utility.GetWebWithSystemPermissions(SPContext.Current.Web);
        SPList Decision_List = web.GetList(Utility.GetServerRelativeUrl(web) + "Lists/Decisions");
        SPFieldUserValue boss = new SPFieldUserValue(web, this.ListItem["Bosses"].ToString()); // Can't use ListItem too
        SPListItem item = Desicion_List.GetItemById(id);

    }
  }
}

我无法在 class 中使用 "ListItem"。

所以;

如何从部分 class 访问我的列表项?

如何在 ascx 中使用 boss 变量?

我想要这个是因为我想在 ascx 文件中比较 currentUser.ID 和 boss.User.ID 并在模板上显示特殊字段。

提前致谢

如果你想在用户控件中获取当前的SharePoint ListItem,我们可以使用下面这行代码。

 SPListItem listItem = SPContext.Current.ListItem;

如果 "ListItem" 不是 SharePoint ListItem,我建议您提供 UserControl.ascx 文件中的代码以供进一步研究。

    protected int GetBossId()
    {
        return new SPFieldUserValue(SPContext.Current.Web, SPContext.Current.ListItem["Bosses"].ToString()).LookupId;
    }

全部删除。并编写这个函数。现在你可以在 Usercontrol.ascx

获得 BossID