繁体   English   中英

GridView不在数据表中显示所有列

[英]GridView is not displaying all columns in DataTable

我有一个由MDX查询填充的数据表。 我想将该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

资产和价值是MDX查询中的汇总度量。

在重命名列之后,然后将DataTable绑定到GridView:

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

绑定DataTable之后,只有一部分列显示在GridView中。 具体而言,将显示MDX查询中除“测量”列以外的所有列。

任何帮助,将不胜感激。

问题最终是MDX查询将用“测量”结果的“对象”类型填充DataTable,而AutoGenerateColumns不支持该类型。 为了解决这个问题,我在绑定到GridView之前利用了这里的解决方案来更改DataType: 如何更改DataTable中DataColumn的DataType?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM