【发布时间】:2011-06-07 02:06:50
【问题描述】:
我想显示某个 ListItem 的所有字段。这包括 LookUpFields 和 ChoiceFields。但我似乎只能显示文本字段,如标题。如何显示我的 ListItem 的所有字段? 问题是当我尝试以显示“标题”的方式显示列表项的其他字段时出现错误,就好像我输入的字符串不作为该列表项中的字段存在一样。但它们确实存在并且充满了价值! 在不出现 ObjectReference 错误的情况下显示列表项的自定义字段的好方法是什么? 我也收到此错误:字典中不存在给定的键。
private void foo()
{
using (ClientContext context = new ClientContext(ApplicationContext.Current.Url))
{
_list = context.Web.Lists.GetByTitle("MyList").Title);
_items = _list.GetItems(CamlQuery.CreateAllItemsQuery());
context.Load(_items);
context.ExecuteQueryAsync(
new ClientRequestSucceededEventHandler(OnListItemsRequestSucceeded),
new ClientRequestFailedEventHandler(OnListItemsRequestFailed));
}
}
private void OnListItemsRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args)
{
// this is not called on the UI thread
Dispatcher.BeginInvoke(ShowListItemDetails);
}
public void ShowListItemDetails()
{
foreach (ListItem i in _items)
{
TextBox_Details.Text += i["Title"].ToString() + Environment.NewLine;
// Now the rest of the fields of this item.
}
}
编辑:还有一个大问题是我无法让调试器工作。此代码在本地 Sharepoint 站点上作为 Silverlight Webpart 运行。我将调试器附加到 iexplorer.exe,但它不会中断。 如果我能让调试器工作,那将是一个很大的帮助。
【问题讨论】:
-
而问题实际上是什么?当您转储更多字段时会出现什么问题?您在处理非文本字段时遇到什么问题?
-
Ondrej 可能的意思是您应该向我们提供您在处理非文本字段时遇到的错误。另外:在你的 foreach ListItem 循环中设置一个断点,你可以访问所有字段(只是为了看看它们在那里)。
标签: silverlight sharepoint com web-parts