0
votes

I create a DataTable with the column names: Car Make, Car Model, Car Id

I then bind the DataTable to an aspx Gridview ( Devexpress ).

I then later on in the program, want to change the DataTable to have fieldnames of:

Airplane Make, Airplane Model, Airplane Id

I bind it to the same Gridview and end up with a message like:

A field or property with name 'Car Make' was not found in the selected data source. Possible causes of this error may be the following: an incorrect or case-insensitive spelling of the grid column name; assigning a wrong or not properly initialized data source to the grid.

I have tried to do:

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

This clears out the gridview totally without adding my new records. Any ideas anyone?

1
Do you have the AutoGenerateColumns property set to true? - Josh Darnell
Which Event did you bind the grid earlier, and in which event did ypu change the column names? please be more clear. - Akhil
Akhil, i bound the property via button on_click event - user532104

1 Answers

2
votes

Toggling the AutoGenerateColumns property seems to work (As silly as it is!):

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