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

时间:2018-08-01 13:30:39

标签: c# sharepoint listitem splistitem splist

这是我的UserControl.ascx.cs子类

   {
        “status_code”:400,
        “reason_phrase”:”bad request”
        “Error_code”:”error_code_that_needs_be_handled_by_custom_message”
        “error_message”:”put the custom message over here”
   }

我不能在此类中使用“ ListItem”。

所以;

如何从部分课程访问列表项?

如何在ascx中使用老板变量?

我想这样做是因为我想将ascx文件中的currentUser.ID与boss.User.ID进行比较,并在模板上显示特殊字段。

预先感谢

2 个答案:

答案 0 :(得分:0)

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

 SPListItem listItem = SPContext.Current.ListItem;

如果“ ListItem”不表示SharePoint ListItem,建议您在UserControl.ascx文件中提供代码以供进一步研究。

答案 1 :(得分:0)

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

全部删除。并编写此功能。现在您可以在Usercontrol.ascx上获得BossID