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

Find Sort Column Number

2 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Duneel
Top achievements
Rank 2
Duneel asked on 11 Jan 2011, 08:38 PM
Hi,

I need to find the column index in the RadGrid that was clicked for sorting. I should be able to have my logic under radGrid_ItemComand when e.CommandName = "Sort"

The reason is my grid is dynamically created and i dont know what my colums are. So at least if I can find the clicked column number then I can implement the rest of the logic.

Thanks!
Duneel

2 Answers, 1 is accepted

Sort by
0
Accepted
Mike Nogen
Top achievements
Rank 1
answered on 11 Jan 2011, 09:37 PM
Hello!

I really don“t know if this is the best practice solution but I think it should work for you

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
       {
           if (e.CommandName == RadGrid.SortCommandName)
           {
              LinkButton sorting = (LinkButton)e.CommandSource;
              int orderIndex = this.RadGrid1.MasterTableView.GetColumn(sorting.CommandArgument).OrderIndex;
                
           }
       }
0
Duneel
Top achievements
Rank 2
answered on 11 Jan 2011, 10:21 PM
Hello Mike,

Thanks for the code sample. Yeah this will also work. I set the SortExpression of each dynamic bound column to a unique value and i was able to get that in RadGrid1_Itemcommand event using e.CommandArgument.

Thanks,
Duneel
Tags
Grid
Asked by
Duneel
Top achievements
Rank 2
Answers by
Mike Nogen
Top achievements
Rank 1
Duneel
Top achievements
Rank 2
Share this question
or