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

Reorder columns in code behind

1 Answer 275 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mat
Top achievements
Rank 1
Mat asked on 17 Feb 2015, 09:58 AM
Hi all,

I'd like to reorder my edit column to put it on the far right of my grid.

My radGrid is generated like this :

<MasterTableView>
<Columns>   
<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" ><ItemStyle CssClass="MyImageButton" width="20" /></telerik:GridEditCommandColumn>
</Columns>
</MasterTableView>

Then I add up dynamically columns in the even NeedDataSource.

The problem is, My edit column is on the far left and not on the far right. I've tried the following snippet without much success :

protected void radGridTranslation_DataBound(object _sender, EventArgs _event)
{
    GridColumnCollection l_columns = radGridTranslation.MasterTableView.Columns;
    GridColumn l_editColumn = l_columns.FindByUniqueName("EditCommandColumn");
    if (l_editColumn != 
    {
        l_editColumn.OrderIndex = 
    }  
}

I've found this example :http://www.telerik.com/help/aspnet-ajax/grid-reordering-columns.html

But I don't want to have to use a script to change anything. I should be able to do it right in my Code behind.

Could you help me please ?

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 20 Feb 2015, 10:32 AM
Hello Stéphane,

Please note that using declaratively defined columns in combination with programmatically created columns is not supported. You will need to create them either entirely on the mark-up or in the code-behind (during the Page_Init event handler, not NeedDataSource):
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html#Section22

In case you are using auto-generated columns, you can use the approach demonstrated in the attached web site sample in order to change the position of the column.

Hope this helps.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Mat
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or