0

我创建了一个可视化 Web 部件并在 Grid 中加载列表。现在,当用户 A 登录时,它必须只显示用户 A 创建的项目。用户 B 它必须只显示属于用户 b 的项目。这是我编写的代码。它显示所有项目,而与登录用户无关。谁可以帮我这个事

public void Displaylistdata()
        {
           // System.Diagnostics.Debugger.Break();

            DataTable dt = new DataTable();
            var oSPWeb = SPContext.Current.Web;
            SPList oSpList = oSPWeb.Lists["Participation at a Glance"];
            string strCreatedby = SPContext.Current.Web.Author.Name;
            SPQuery oQuery = new SPQuery();
            oQuery.Query = "<Query><Where><Eq><FieldRef Name='Author' /><Value Type='User'>" + strCreatedby + "</Value></Eq></Where></Query>";
            SPListItemCollection collListItems = oSpList.GetItems(oQuery);

            DataTable dts = collListItems.GetDataTable();

            if (dts != null)
            {
                Gridview1.GridLines = GridLines.None;
                Gridview1.DataSource = dts;
                Gridview1.DataBind();
                Controls.Add(Gridview1);
            }

            else`enter code here`
            {

                lbl_noact.Visible = true;
                lbl_noact.Text = "We apologize there are no times currently available.";

            }


        }
4

1 回答 1

0

嗨,我已通过如下更改我的骆驼查询来修复。以前数据类型是 USER 但当我更改为字符串时,它就像一个魅力:-)

        DataTable dt = new DataTable();
        var oSPWeb = SPContext.Current.Web;
        SPList oSpList = oSPWeb.Lists["Participation at a Glance"];
        string strCreatedby = SPContext.Current.Web.CurrentUser.Name;
        SPQuery oQuery = new SPQuery();
        oQuery.Query = @"<Where><Eq><FieldRef Name='Author' /><Value Type='String'>" + strCreatedby + "</Value></Eq></Where>";
        SPListItemCollection collListItems = oSpList.GetItems(oQuery);
于 2013-04-04T03:42:36.407 回答