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

[Solved] Programmatic and Autogenerated Columns

8 Answers 235 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eve Cunning
Top achievements
Rank 1
Eve Cunning asked on 12 Oct 2009, 09:02 PM
Hello,

I'm working on a webpage that contains, among other controls, a dropdownlist and a radgrid.  Whenever an item is selected in the dropdownlist, inside the event handler the radgrid uses that selection to retrieve its data.

The radgrid always contains a clientselectcolumn and two button columns (Edit and View).  Beyond those "constant" ones the rest of the columns are based on the retrieved data, and they vary.  The data columns are sortable, resizeable, and reorderable.  The grid is also filtered from the codebehind.

I am also loading and saving column information for these data columns (size, order, etc) associated with the ddl selection.  Sometimes the columns do have saved settings for the ddl selection, and sometimes they do not (for these I apply some default settings values).

I have tried a number of different approaches from the various RadGrid examples and postings, but none entirely match what I'm doing, and none entirely work.  I am having page lifecycle problems and/or postback problems (some things work and some things don't).

Generally, what kind of approach would you suggest here?  Particularly:
  • How should the "constant" columns be created (in aspx, in the codebehind/at what point, or...)?
  • How should the data columns be generated and at what point (autogenerated, programmatically/at what point...)?
  • When should any saved column settings be applied (at databound, at creation time...)?
  • How do I keep from losing the constant columns on a postback, say, on column reorder?

I appreciate any insight you can provide.  Please let me know if I need to provide more information.

Thanks!
Eve

8 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 13 Oct 2009, 12:48 PM
Hi Eve,

Please examine this online help article which shows how to implement the requested behavior.
Programmatic creation

Let me know if it helps.

All the best,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Eve Cunning
Top achievements
Rank 1
answered on 13 Oct 2009, 06:32 PM
Hi Pavlina,

I had already looked at that article and a few others, but hadn't found everything I need in combination.

However, I spent today working with it, and managed to get everything working except for reloading the saved column order.  

The constant columns are declared in aspx and the data columns are autogenerated.  I am loading the data columns' order with the other settings and assigning the order index there, taking care that the index starts with the index following all the constant columns, and that no indices are duplicated or omitted.

However, when the grid displays on the screen, the items are not in the order they were assigned.  They are also not in the order they appear in the AutogeneratedColumns array, so I'm not sure where this order is coming from.

Is there some trick to assigning to OrderIndex for a column?  Are autogenerated columns reorderable in this way?  Must these columns be reordered at a particular point in the lifecycle to have an effect?

Thank you,
Eve
0
Pavlina
Telerik team
answered on 14 Oct 2009, 10:06 AM
Hello Eve,

You can try out swapping of columns to reorder them as shown in the help link below. Where the UniqueName for Autogenerated columns would be the DataField itself.
http://www.telerik.com/help/aspnet-ajax/grdreorderingcolumns.html(Reordering columns programmatically)

Sincerely yours,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Eve Cunning
Top achievements
Rank 1
answered on 15 Oct 2009, 01:59 PM
I had seen that example as well.

My grid is set to allow client-side reordering and columnviewstate is disabled.  I am loading properties in an indexchanged event handler for a dropdownlist.  The properties all save properly, and all also load properly except for column order on the autogenerated columns.

I'm reordering the autogenerated columns sequentially using the OrderIndex property, and have verified that the columns are at the correct order number (the OrderIndex for the last declared column + 1), the numbers are sequential, and there are no gaps.

However, RadGrid seems to be ignoring that reordering, and rendering the columns in their original order.

Is there a certain event during which the columns must be reordered to take effect?  Is there something the grid would be doing to reset the OrderIndex values?

Thank you,
Eve
0
Eve Cunning
Top achievements
Rank 1
answered on 16 Oct 2009, 03:48 PM
Pavlina,

An interesting development--reordering the column indices does not work, but using SwapColumns does.  I do not know why there is a difference; perhaps because the columns are autogenerated?

So I will rework my code using SwapColumns, but I would still be curious to know why changing OrderIndex does not work.

Best regards,
Eve
0
Pavlina
Telerik team
answered on 20 Oct 2009, 01:28 PM
Hello Eve,

When working with disabled ViewState (see Optimizing ViewState usage), RadGrid must rebind on each page load to maintain its state. Because of this, client-side column reordering does not work as expected in this mode. If you want to enable column re-ordering when working with EnableViewState = false for the grid, ensure that you set ClientSettings.ReorderCoumnsOnClient to False in order to reorder the grid columns on the server.

All the best,

Pavlina
the Telerik team

 


Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Eve Cunning
Top achievements
Rank 1
answered on 20 Oct 2009, 01:42 PM
Pavlina,

I've got EnableViewState=true and EnableColumnViewState=false.  Do these same rules apply?

Thanks,
Eve
0
Pavlina
Telerik team
answered on 23 Oct 2009, 10:11 AM
Hello Eve,

I suggest you set ClientSettings.ReorderCoumnsOnClient to False in order to reorder the grid columns.
If the issue still persist, please open a formal support ticket and send us a simple working project that reproduced this erroneous behavior. Thus we could help you to find quick solution/fix.

Best wishes,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Eve Cunning
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Eve Cunning
Top achievements
Rank 1
Share this question
or