GridView未显示DataTable中的所有列



我有一个由MDX查询填充的DataTable。我想将该DataTable绑定到GridView并显示返回的所有数据。我的GridView定义如下:

<asp:GridView ID = "gvResults" runat="server" AutoGenerateColumns="true" />

MDX查询调用如下:

DataTable mdxResults = new DataTable();
CellSet cellSet;
AdomdCommand command = new AdomdCommand();
strCommand = "SELECT NON EMPTY({[Measures].[Assets Distinct Count], [Measures].[Value]}) " + 
"ON COLUMNS, NONEMPTY({[Organization].[Org Id].[Org Id]*[Location].[Loc Id].[Loc Id]}) " + 
"ON ROWS FROM [database]"
command.Connection = _CurrentConnection;
command.CommandText = strCommand;
cellSet = command.ExecuteCellSet();
AdomdDataAdapter dataAdapter = new AdomdDataAdapter(command);
objDataAdapter.Fill(mdxResults);

可以从MDX查询生成的DataTable示例:

Organization   Location      Assets     Value
Org A          Los Angeles   12         320000
Org B          San Jose      6          21000

Assets和Value是MDX查询中的聚合度量。

在我重命名列之后,DataTable被绑定到GridView:

gvResults.DataSource = mdxResults;
gvResults.DataBind();

在我绑定DataTable之后,只有列的子集显示在GridView中。具体而言,将显示MDX查询中除Measure列之外的所有列。

如有任何帮助,我们将不胜感激。

最终的问题是MDX查询将用AutoGenerateColumes不支持的度量值结果的类型Object填充DataTable。为了纠正这一问题,我在绑定到GridView之前使用了此处的解决方案来更改DataType:如何更改DataTable中DataColumn的DataType?

最新更新