我创建了一个可视化 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.";
}
}