【问题标题】:GridView is not displaying all columns in DataTableGridView 未显示 DataTable 中的所有列
【发布时间】:2014-11-28 13:31:04
【问题描述】:

我有一个由 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 列之外的所有列。

任何帮助将不胜感激。

【问题讨论】:

  • 插入其余的 GridView 代码和 DataTable 示例
  • 能否显示调用查询的代码,然后将 DataTable 的结果绑定到 Gridview..?

标签: c# asp.net


【解决方案1】:

问题最终是 MDX 查询将为 AutoGenerateColumns 不支持的 Measure 结果填充类型为 Object 的 DataTable。为了纠正这个问题,我在绑定到 GridView 之前使用了这里的解决方案来更改 DataType: How To Change DataType of a DataColumn in a DataTable?

【讨论】:

    猜你喜欢
    • 2013-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    • 2012-05-10
    • 1970-01-01
    相关资源
    最近更新 更多