SharePoint list.items.GetDataTable 列名称与字段名称不匹配
我将 SPGridView 绑定到 SPList。 正如代码示例所示,我使用以下代码基于列表创建数据视图。
dim data as DataView = myList.Items.GetDataTable.DefaultView
grid.DataSource = data
etc...
我发现结果数据视图中的列名称并不总是与 SPList 中定义的源字段匹配。 例如,我有名为
- Description
- ReportItem
ReportStatus
的列这些显示在结果数据视图中,列名称如
- ReportType0
- ReportStatus1
这让我认为我定义了重复的字段名称,但这似乎并不存在是这样的。
似乎我在这里错过了一些基本的东西? 谢谢。
I am binding an SPGridView to a SPList. As code samples suggest, I am using the following code to create a dataview based on the list.
dim data as DataView = myList.Items.GetDataTable.DefaultView
grid.DataSource = data
etc...
What I am finding is that the column names in the resulting dataview do not always match the source fields defined in the SPList. For example I have columns named
- Description
- ReportItem
ReportStatus
these show up in the resulting dataview with column names like
- ReportType0
- ReportStatus1
This leads me to think that I have duplicate field names defined, but that does not seem to be the case.
Seems like I am missing something fundamental here?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
GetDataTable
方法返回internalName
(或staticName
- 我无法确定是哪一个,但它们通常是相同的)表示形式列,而不是您在 Web 界面中看到的Title
表示形式。 我相信GetDataTable
在幕后执行 CAML 查询,并且您必须使用该internalName
在 CAML 中进行字段引用。此博客更详细地讨论它。
The
GetDataTable
method is returning theinternalName
(orstaticName
-- I can't remember for sure which but they are frequently the same) representation of the columns, rather than theTitle
representation, which is what you see in the Web interface. I believeGetDataTable
does a CAML query under the covers, and you have to use thatinternalName
for field references in CAML.This blog talks about it in a little more detail.
所以我在我的博客上发布了这一点,但我写了一个你可以使用的小实用方法,在你获取数据表之后,它基本上将 DataTable 中的列名称重新映射为其友好名称。
希望有帮助!
So I posted about this on my blog, but I wrote a little utility method that you can use, right after you get the data table it basically remaps the column names in the DataTable to their friendly names.
Hope that helps!
您还可以做的(如果您使用的是 .NET 3.5)是使用匿名类型并对其进行绑定。 如果您这样做,您可能还想使用 Linq 数据源。
我在此处发表了一篇文章来解释这一点。
What you also could do (if you´re using .NET 3.5) is to use an anonymous type and bind against that. If you´re doing this you might wanna go with a Linq DataSource as well.
I have made a post that explains this here.