This is a migrated thread and some comments may be shown as answers.

[Solved] Extra columns when binding JSON array on client side with dynamically created columns

1 Answer 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 20 Feb 2013, 06:13 PM
I'm trying to implement client-side binding to a JSON array via the following JS:

var tableView = $find("<%= gridView.ClientID %>").get_masterTableView();
tableView.set_dataSource(GridData);
tableView.dataBind();

My columns are dynamic since they are controlled via configuration, so I have to create them on the server during Page_Load by creating GridBoundColumn instances and adding them to the grid's Columns collection (see simplified example):

GridBoundColumn column = new GridBoundColumn();
gridView.Columns.Add(column);
column.DataField = fieldBinding;
 column.UniqueName = uniquename;
column.SortExpression = fieldBinding;
column.HeaderText = fieldLabel;
gridView.Columns.Add(column);

I've found that to get any data to show up, I also have to do a preliminary data binding on Page_Load:
gridView.MasterTableView.DataSource = new string[] { };
gridView.DataBind();

Overall this works and my binding does populate, but I end up with an extra "Items" column on the right side that I cannot hide.  Getting rid of the server-side preliminary binding eliminates the extra column, but at the cost of preventing the client-side binding from occurring.  There doesn't seem to be any way to hide this extra column since it doesn't show up in the Columns collection during the lifespan of Page_Load.

Any ideas? 

1 Answer, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 20 Feb 2013, 06:18 PM
Ack, never mind.  I had accidentally left AutoGenerateColumns turned on.  My apologies, but hopefully this helps someone else. :-)
Tags
Grid
Asked by
David
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Share this question
or