SharePoint从集合中获取当前列表项

时间:2011-01-08 10:28:40

标签: sharepoint-2010

我使用c#为sp 2010创建了一个小应用程序,我正在做的是从一个集合中获取项目并查看我想要的特定字段,问题是当我点击一个项目时它会显示我分配的每个项目的详细信息对于当前用户,我如何只显示用户点击的当前项目的详细信息,下面是我的代码...谢谢

foreach (SPListItem myItem in myItemCollection)

  {
  if (myList.Fields.ContainsField("Title"))
  {
    EntreeListItemDetailNameValue l = lGrp.AddListItem<EntreeListItemDetailNameValue>();
    SPField myField1 = myList.Fields.GetField("Title");
    l.Name = myField1.Title;
    try
    {
      l.Value = myField1.GetFieldValueAsText(myItem["Title"]);


    }
    catch
    {
      l.Value = "";
    }

  }
  if (myList.Fields.ContainsField("Priority"))
  {
    EntreeListItemDetailNameValue l2 = lGrp.AddListItem<EntreeListItemDetailNameValue>();
    SPField myField = myList.Fields.GetField("Priority");
    l2.Name = myField.Title;

    try
    {
      l2.Value = myField.GetFieldValueAsText(myItem["Priority"]);
    }
    catch
    {
      l2.Value = "";
    }

1 个答案:

答案 0 :(得分:0)

你可以使用GetItemById() http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitemcollection.getitembyid.aspx

void list_Click(object sender, EventArgs e) {
    int clickedid = 0; //get the id from the clicked item
    ShowForm(); //show detail form
    DataBind(clickedid); //databind detail form
}

void DataBind(int id) {
    SPListItemCollection myItemCollection = showthing; //load the list items, query using SPQuery, or SPList.Items
    SPListItem item = myItemCollection.GetItemById(id);
    form.Title = item["Title"];
}