【问题标题】:Change the headings of a gridview更改网格视图的标题
【发布时间】:2011-12-19 15:57:37
【问题描述】:

我用列名创建了一个 DataTable: 汽车品牌、汽车型号、汽车 ID

然后我将 DataTable 绑定到一个 aspx Gridview (Devexpress)。

我稍后在程序中,想将 DataTable 更改为具有以下字段名称:

飞机品牌、飞机型号、飞机 ID

我将它绑定到同一个 Gridview 并最终得到如下消息:

在所选数据源中找不到名称为“汽车制造”的字段或属性。此错误的可能原因可能如下: 网格列名称拼写错误或不区分大小写;将错误或未正确初始化的数据源分配给网格。

我已经尝试过:

    ASPxGridView1.Columns.Clear();
    ASPxGridView1.DataSource = null;
    ASPxGridView1.DataBind();
    ASPxGridView1.DataSource = ds.Tables[0];
    ASPxGridView1.DataBind();

这完全清除了 gridview 而不添加我的新记录。有什么想法吗?

【问题讨论】:

  • 您是否将AutoGenerateColumns 属性设置为true
  • 您之前在哪个事件中绑定了网格,在哪个事件中 ypu 更改了列名?请更清楚。
  • Akhil,我通过按钮 on_click 事件绑定了属性

标签: c# gridview aspxgridview


【解决方案1】:

切换 AutoGenerateColumns 属性似乎有效(尽管它很愚蠢!):

ASPxGridView.Columns.Clear();
ASPxGridView.AutoGenerateColumns = false;
ASPxGridView.AutoGenerateColumns = true;
ASPxGridView.DataSource = ds;
ASPxGridView.DataBind();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-03
    • 1970-01-01
    • 1970-01-01
    • 2012-01-19
    相关资源
    最近更新 更多