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

Changing sort on already sorted column causes different column to be sorted

4 Answers 138 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Sean Severson
Top achievements
Rank 1
Sean Severson asked on 07 May 2013, 08:26 PM
I have a radGrid in a user control which is loaded dynamically into my page via code.  I am able to sort any of the sortable columns in ascending order by clicking the column header.  when I attempt to change the sort to descending by clicking a second time on an already sorted column, the sortable column immediately preceding the column I clicked on gets sorted in ascending order.  This does not happen when this same user control is referenced directly in the page (not loaded dynamically).  Vewstate is enabled.

This is just really odd behaviour which has me stumped.  i thought it might be that the sorting was attempting to use a column index for sorting, and was somehow using the wrong index.  I added a breakpoint to the grid's SortCommand event handler and the information in the GridSortCommandEventArgs (e) says that the sort expression that will be applied on the second click is from the preceding column, not the column I clicked.  I am not hiding or showing columns and the column that is ultimately sorted is not necessarily the column immediately preceding the column I clicked...it is the preceding column that is sortable.

I have attached screen shots of my grid after the first sort and second sort on the same Status column.  In these screen shots, the Recipients column is not sortable.

Thanks for the help!

Sean Severson

4 Answers, 1 is accepted

Sort by
0
Sean Severson
Top achievements
Rank 1
answered on 09 May 2013, 12:41 PM
After further research (hope this isn't too messy)...

NOTE: The RadGrid is contained in a user control.  The problem is when the user control is loaded into the page via code.  I will refer to the user control, but the problem is really in the RadGrid.  See prior post for screen shots of the RadGrid.

I took a look at the RadGrid's control ids as they are rendered after each sort attempt.  The controls I am referring to are the anchor tags in the headers used to trigger the sort.  For the user control that is referenced in the page (this user control containing the radgrid is used on another page without any issues but is not loaded from code there), the radGrid's control ids do not change between postbacks.  The id that is the target of the postback (the id being from the anchor tag of the column I wish to sort) will point to the same control before and after the postback.

For the user control that is loaded via code, the radGrid's control ids change between postbacks.  The id that is the target of the postback does not change, but the control that that id points to does.  For example, when a sort is applied to the Status column, the id of the anchor in the header that will trigger the postback for sorting the Status column will be ctl00_Content_ContactMainArea1_pnlFormLetterInfo_i0_i0_ucLetters_grdFormsLetters_ctl00_ctl02_ctl00_ctl01.  When a second sort (from asc to desc) on the Status column is attempted, the user control containing the RadGrid is recreated via code (on page load) to its default, which means the default sort is applied to the grid and the UI control tree is built-up accordingly.  At this point, the id of the Status column’s anchor is ctl00_Content_ContactMainArea1_pnlFormLetterInfo_i0_i0_ucLetters_grdFormsLetters_ctl00_ctl02_ctl00_ctl02 due to the addition of the sort icon that is displayed in the Created Date column (which is the default sort). 

When the target of the postback is then processed, the target (id of the anchor) now points at the Document Name column anchor (preceding control which now has the id of ctl00_Content_ContactMainArea1_pnlFormLetterInfo_i0_i0_ucLetters_grdFormsLetters_ctl00_ctl02_ctl00_ctl01) which causes the SortCommand to sort the Document Name column.

ViewStateMode on the RadGrid is set to Enabled and ViewState is also enabled in the page.

I would think that the grid would be returned to the same state it was in after the prior postback (due to applying ViewState) before the SortCommand event is processed.   I must be missing something.  Or, must I handle the sort manually when the grid is loaded via code?

Sean Severson

0
Eyup
Telerik team
answered on 13 May 2013, 07:55 AM
Hello Sean,

I have prepared a sample RadGrid web site to test the described behavior. On my side sorting works correctly. Can you please run the attached application and let me know if it works as expected on your end, too?

Regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Sean Severson
Top achievements
Rank 1
answered on 13 May 2013, 01:08 PM
Eyup,

Your provided sample works just fine, and I probably did not give a good description of how my page is being built up.  In the aspx I have a RadPanelBar.  When I need to add the RadGrid to my page, it is added to the panelbar via code.  So, my grid is inside a user control that is inside a panel, inside a panel bar.

Here is the code I use to add the panel.  it is contained in a class call PanelBarFactory...
 
    Public Function GetFormsLettersPanels() As RadPanelItem
        Dim panelItem As New RadPanelItem("Forms & Letters")
        panelItem.Expanded = True
        panelItem.ForeColor = Drawing.Color.Maroon
  
        Dim subItem As New RadPanelItem
        subItem.Value = "FormsLetters"
  
  
        panelItem.Items.Add(subItem)
        Return panelItem
    End Function

I add the user control into the panel with this ...

Dim ctlFormsLetters As UserControl = CType(Page.LoadControl(panelFactory.GetFormsLettersControl()), UserControl)
  
Dim panelFormsLetters As New RadPanelItem
panelFormsLetters = panelFactory.GetFormsLettersPanels()  'this code is shown above
  
panelFormsLetters.Controls(0).Controls.Add(ctlFormsLetters)

My workaround has been to eliminate the loading of the user control via code and just hide and show the control as needed.

Sean Severson
0
Eyup
Telerik team
answered on 16 May 2013, 10:09 AM
Hello Sean,

I am glad that you have managed to overcome the issue.

In order to assist you further, please prepare a very basic runnable sample application demonstrating the problematic behavior and open a support ticket to send it to us. Thus, we will be able to further debug and analyze the project and suggest a proper solution.

Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
ComboBox
Asked by
Sean Severson
Top achievements
Rank 1
Answers by
Sean Severson
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or