开发者

SharePoint get current list item from a collection

开发者 https://www.devze.com 2023-02-03 17:19 出处:网络
ive made a small app using c# for sp 2010, what i am doing is getting items from a collection and viewing specific fields that i want to, the problem is when i click an item it shows me the details of

ive made a small app using c# for sp 2010, what i am doing is getting items from a collection and viewing specific fields that i want to, the problem is when i click an item it shows me the details of every item assigned to the current user, how can i show only the details of the current item which the user clicks, below is my code...thanks

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&l开发者_运维百科t;EntreeListItemDetailNameValue>();
    SPField myField = myList.Fields.GetField("Priority");
    l2.Name = myField.Title;

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


You could use 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"];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消