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

Duplicate Columns from ViewState

1 Answer 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
stoneym
Top achievements
Rank 1
stoneym asked on 19 Aug 2008, 02:07 PM
I have been debugging this for a day and I am getting nowhere.  Hoping I can get some info on how the viewstate for the Grid should work.

I have a CompositeControl that has a RadGrid added to the Child Controls in teh CreateChildControls override.  I set a number of properties, wire up some events, and then add some columns manually to teh MasterTableView column Collection.  On teh initial load of the page the colums are there as they should be.  Not every postback to the page will populate the grid.  But with every postback, I get extra columns in my grid.  If I add 2 colums to my grid manually in CreateChildControls, that is how many are added to the grid as extras with each postback.

I have stepped through the code (we have Telerik source) and the extra columns are being added in teh Load ViewState. 

What am I doing wrong?  Should I not be re-adding my columns to the Column Collection if it is a Post Back?  What if my Post Back causes the columsn that are in teh grid to change?  I should be able to create a whole different set of columns on post back.  Then I wouldn't want viewstate, but if the columns stayed the same, I do.

Also, once my grid is databound to an object datasource and displays data, the data is correct for my original 2 columns, but not for the extras added from viewstate.

1 Answer, 1 is accepted

Sort by
0
stoneym
Top achievements
Rank 1
answered on 19 Aug 2008, 03:29 PM
nevermind.  seems that if you add your grid to the controls collection of the parent before filling your masterviewtable this happens.

so don;t add your radgrid to the control collection before you are done with your columns.
Tags
Grid
Asked by
stoneym
Top achievements
Rank 1
Answers by
stoneym
Top achievements
Rank 1
Share this question
or