Detail Table of RadGrid not sorting descending

3 posts, 1 answers
  1. scott
    scott avatar
    35 posts
    Member since:
    Mar 2011

    Posted 04 Jun 2012 Link to this post

    I made a sample two-level grouping grid based on a page I am using and am filling it with sample data in the attached code. The first level grouping is sorting ascending and descending just fine. The second level grouping seems to only sort ascending successfully. The re-sort to descending is failing. I've attempted a few different ways to fix this, but they haven't been fully successful. Any help would be appreciated.

    Code behind:

    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Web.HttpContext     
    Imports Telerik.Web.UI
    Imports System.IO
     
    Partial Class _TestSort
        Inherits System.Web.UI.Page
     
    #Region " Variables"
        Private _dvMarksFlat As DataView = Nothing
     
    #End Region
     
    #Region " Control Events"
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If IsPostBack Then
                hdnLoadDone.Value = "N"
            End If
            If hdnLoadDone.Value <> "Y" Then
                LoadData()
                rgMarks.Rebind()
                hdnLoadDone.Value = "Y"
            End If
        End Sub
     
    #End Region
         
    #Region " Marks Grid"
     
        Public Function GetData_MarksTopGroup(ByRef dtMarksFlat As DataTable) As DataTable
            Dim dvMarks As DataView = dtMarksFlat.DefaultView
            Dim dtMarksTopGroup As DataTable = dvMarks.ToTable("" ,True, "SCHOOL_YEAR", "GRADE_LEVEL_CODE", "SEMESTER_TERM", "SEMESTER_TERM_Nm", _
                                                                               "ATTENDING_DISTRICT_ID_Nm", "ATTENDING_SCHOOL_ID_Nm")
            Return dtMarksTopGroup
        End Function
     
        Protected Sub rgMarks_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs)
            Try
                If _dvMarksFlat isnot Nothing Then
                    Dim dtMarksFlat As DataTable = _dvMarksFlat.ToTable
                    Dim dtMarksTopGroup As DataTable = GetData_MarksTopGroup(dtMarksFlat)
                    rgMarks.DataSource = dtMarksTopGroup
                    lblNoData.Visible = False
                Else
                'No Data
                    lblNoData.Visible = True
                    rgMarks.Visible = False
                End If
            Catch ex As Exception
            'Hide data/controls if error
     
            End Try
     
        End Sub
     
        Protected Sub rgMarks_DetailTableDataBind(ByVal source As Object, ByVal e As GridDetailTableDataBindEventArgs)
            Dim dataItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)
            Select Case e.DetailTableView.Name
                Case "Course"
                    If _dvMarksFlat isnot Nothing Then
                        Dim dtMarksFlat As DataTable = _dvMarksFlat.ToTable
     
                        Dim SCHOOL_YEAR As String = dataItem.GetDataKeyValue("SCHOOL_YEAR").ToString()
                        Dim GRADE_LEVEL_CODE As String = dataItem.GetDataKeyValue("GRADE_LEVEL_CODE").ToString()
                        Dim SEMESTER_TERM As String = dataItem.GetDataKeyValue("SEMESTER_TERM").ToString()
                        Dim ATTENDING_DISTRICT_ID_Nm As String = dataItem.GetDataKeyValue("ATTENDING_DISTRICT_ID_Nm").ToString()
                        Dim ATTENDING_SCHOOL_ID_Nm As String = dataItem.GetDataKeyValue("ATTENDING_SCHOOL_ID_Nm").ToString()
     
                        Dim dvMarksFiltered As DataView = dtMarksFlat.DefaultView
                        dvMarksFiltered.RowFilter = "SCHOOL_YEAR='" & SCHOOL_YEAR & "' AND GRADE_LEVEL_CODE='" & GRADE_LEVEL_CODE & "' AND SEMESTER_TERM='" _
                            & SEMESTER_TERM & "' AND ATTENDING_DISTRICT_ID_Nm='"& ATTENDING_DISTRICT_ID_Nm & "' AND ATTENDING_SCHOOL_ID_Nm='"& ATTENDING_SCHOOL_ID_Nm & "'"
     
                        e.DetailTableView.DataSource = dvMarksFiltered.ToTable
     
                    End If
            End Select
        End Sub
     
        Private Sub rgMarks_DataBound(sender As Object, e As System.EventArgs) Handles rgMarks.DataBound
            If rgMarks.MasterTableView.Items.Count > 0 Then
                rgMarks.MasterTableView.Items(0).Expanded = True
            End If
        End Sub
     
    #End Region
     
    #Region " Load Data"
        Public Sub LoadData()
     
            Dim dtMarksTemp As DataTable = GetData_Marks()
            _dvMarksFlat = dtMarksTemp.DefaultView
     
        End Sub
     
        Public Function GetData_Marks(Optional ByRef blnNoData As Boolean = False) As DataTable
            Dim dtMarksFlat As New DataTable
     
            dtMarksFlat.Columns.Add("SCHOOL_YEAR", GetType(String))
            dtMarksFlat.Columns.Add("SEMESTER_TERM", GetType(String))
            dtMarksFlat.Columns.Add("SEMESTER_TERM_Nm", GetType(String))
            dtMarksFlat.Columns.Add("COURSE_CODE", GetType(String))
            dtMarksFlat.Columns.Add("COURSE_CODE_Nm", GetType(String))
            dtMarksFlat.Columns.Add("LOCAL_COURSE_CODE", GetType(String))
            dtMarksFlat.Columns.Add("COURSE_MARK", GetType(String))
            dtMarksFlat.Columns.Add("EFFORT_DESCRIPTOR", GetType(String))
            dtMarksFlat.Columns.Add("GRADE_LEVEL_CODE", GetType(String))
            dtMarksFlat.Columns.Add("CREDIT_ATTEMPTED", GetType(String))
            dtMarksFlat.Columns.Add("CREDIT_EARNED", GetType(String))
            dtMarksFlat.Columns.Add("ATTENDING_DISTRICT_ID_Nm", GetType(String))
            dtMarksFlat.Columns.Add("ATTENDING_SCHOOL_ID_Nm", GetType(String))
            dtMarksFlat.Columns.Add("COURSE_MARK_EFFORT", GetType(String))
     
     
            dtMarksFlat.Rows.Add("0910","T1","First Tri-Semester","2052","Algebra I","M3001","B","B","08",Nothing,Nothing,"Test District","Test School", "A")
            dtMarksFlat.Rows.Add("0910","T2","Second Tri-Semester","2052","Algebra I","M3002","B","B","08",Nothing,Nothing,"Test District","Test School", "B")
            dtMarksFlat.Rows.Add("0910","T3","Third Tri-Semester","2052","Algebra I","M3003","B","B","08",Nothing,Nothing,"Test District","Test School", "B")
            dtMarksFlat.Rows.Add("1011","T1","First Tri-Semester","2052","Algebra I","M3001","B","B","09",Nothing,Nothing,"Test District","Test School", "A")
            dtMarksFlat.Rows.Add("1011","T2","Second Tri-Semester","2052","Algebra I","M3002","B","B","09",Nothing,Nothing,"Test District","Test School", "B")
            dtMarksFlat.Rows.Add("1011","T3","Third Tri-Semester","2052","Algebra I","M3003","B","B","09",Nothing,Nothing,"Test District","Test School", "B")
     
            dtMarksFlat.Rows.Add("0910","T1","First Tri-Semester","6101","Spanish I","W2011","B","B","08",Nothing,Nothing,"Test District","Test School", "A")
            dtMarksFlat.Rows.Add("0910","T2","Second Tri-Semester","6101","Spanish I","W2011","B","B","08",Nothing,Nothing,"Test District","Test School", "B")
            dtMarksFlat.Rows.Add("0910","T3","Third Tri-Semester","6101","Spanish I","W2011","B","B","08",Nothing,Nothing,"Test District","Test School", "B")
            dtMarksFlat.Rows.Add("1011","T1","First Tri-Semester","6101","Spanish I","W2011","B","B","09",Nothing,Nothing,"Test District","Test School", "A")
            dtMarksFlat.Rows.Add("1011","T2","Second Tri-Semester","6101","Spanish I","W2011","B","B","09",Nothing,Nothing,"Test District","Test School", "B")
            dtMarksFlat.Rows.Add("1011","T3","Third Tri-Semester","6101","Spanish I","W2011","B","B","09",Nothing,Nothing,"Test District","Test School", "B")
     
            Return dtMarksFlat
        End Function
     
    #End Region
     
    End Class

    Page:

    <%@ Page Language="VB" AutoEventWireup="false" Inherits="myProject._TestSort" title="Student Details" Codebehind="TestSort.aspx.vb" Trace="false" ValidateRequest="false" %>
    <html>
        <body >
            <form id="form1" method="post" runat="server" >
                <telerik:RadFormDecorator ID="FormDecorator1" runat="server" DecoratedControls="all"></telerik:RadFormDecorator>
                <telerik:RadScriptManager ID="RadScriptManager1" runat="server" AsyncPostBackTimeout="600" />
                <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                    <style type="text/css">
                        a:hover {color: #444444; text-decoration: overline underline; background-color: #E1DDC9 !important;}
     
                        .btnDisable .rbPrimaryIcon
                        {
                            background: url(images/loading2.gif) !important;
                        }
                    </style>
                </telerik:RadCodeBlock>
     
                <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" >
                    <AjaxSettings>
                        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                            <updatedcontrols>
                                <telerik:AjaxUpdatedControl ControlID="rgMarks" />
                            </updatedcontrols>
                        </telerik:AjaxSetting>
                        <telerik:AjaxSetting AjaxControlID="rgMarks">
                            <updatedcontrols>
                                <telerik:AjaxUpdatedControl ControlID="rgMarks" />
                            </updatedcontrols>
                        </telerik:AjaxSetting>
                    </AjaxSettings>
                </telerik:RadAjaxManager>
     
                <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" >
                </telerik:RadAjaxLoadingPanel>
         
                <style type="text/css">  
                    /*hide expand icon in panel*/  
                    div.RadPanelBar span.rpExpandHandle
                    {
                        background-image: none !important;
                    }
                </style>
                <table>
                    <tr>
                        <td>
                            <telerik:RadGrid runat="server" ID="rgMarks"
                                OnNeedDataSource="rgMarks_NeedDataSource" OnDetailTableDataBind="rgMarks_DetailTableDataBind" AllowMultiRowSelection="False"
                                AutoGenerateColumns="false"  AllowSorting="True" AllowPaging="true" PageSize="20" ViewStateMode="Enabled"
                                <PagerStyle Mode="NumericPages" />
                                <MasterTableView Name="Term" DataKeyNames="SCHOOL_YEAR,GRADE_LEVEL_CODE,SEMESTER_TERM,ATTENDING_DISTRICT_ID_Nm,ATTENDING_SCHOOL_ID_Nm" ClientDataKeyNames="SCHOOL_YEAR,GRADE_LEVEL_CODE,SEMESTER_TERM,ATTENDING_DISTRICT_ID_Nm,ATTENDING_SCHOOL_ID_Nm"
                                    AllowMultiColumnSorting="True" HierarchyLoadMode="Client" GroupLoadMode="Client" AllowNaturalSort="false" >
     
                                    <DetailTables>
                                        <telerik:GridTableView Name="Course" AllowPaging="true" PageSize="20" DataKeyNames="SCHOOL_YEAR,GRADE_LEVEL_CODE,SEMESTER_TERM,ATTENDING_DISTRICT_ID_Nm,ATTENDING_SCHOOL_ID_Nm"
                                            ClientDataKeyNames="SCHOOL_YEAR,GRADE_LEVEL_CODE,SEMESTER_TERM,ATTENDING_DISTRICT_ID_Nm,ATTENDING_SCHOOL_ID_Nm"
                                            Width="100%" AllowSorting="True" GroupLoadMode="Client" HierarchyLoadMode="Client"
                                            AllowNaturalSort="false" AllowMultiColumnSorting="True"  AllowCustomSorting="true" >
                                            <ParentTableRelation>
                                                <telerik:GridRelationFields DetailKeyField="SCHOOL_YEAR"                MasterKeyField="SCHOOL_YEAR" />
                                                <telerik:GridRelationFields DetailKeyField="GRADE_LEVEL_CODE"           MasterKeyField="GRADE_LEVEL_CODE" />
                                                <telerik:GridRelationFields DetailKeyField="SEMESTER_TERM"              MasterKeyField="SEMESTER_TERM" />
                                                <telerik:GridRelationFields DetailKeyField="ATTENDING_DISTRICT_ID_Nm"   MasterKeyField="ATTENDING_DISTRICT_ID_Nm" />
                                                <telerik:GridRelationFields DetailKeyField="ATTENDING_SCHOOL_ID_Nm"     MasterKeyField="ATTENDING_SCHOOL_ID_Nm" />
                                            </ParentTableRelation>                                                               
                                            <Columns>
                                                <telerik:GridBoundColumn UniqueName="SCHOOL_YEAR"           DataField="SCHOOL_YEAR"         SortExpression="SCHOOL_YEAR"        HeaderText="SCHOOL_YEAR"        Display="false" />
                                                <telerik:GridBoundColumn UniqueName="LOCAL_COURSE_CODE"     DataField="LOCAL_COURSE_CODE"   SortExpression="LOCAL_COURSE_CODE"  HeaderText="LOCAL_COURSE_CODE"  Display="true" />
                                                <telerik:GridBoundColumn UniqueName="COURSE_CODE"           DataField="COURSE_CODE"         SortExpression="COURSE_CODE"        HeaderText="COURSE_CODE"        Display="true" />
                                                <telerik:GridBoundColumn UniqueName="COURSE_CODE_Nm"        DataField="COURSE_CODE_Nm"      SortExpression="COURSE_CODE_Nm"     HeaderText="COURSE_CODE_Nm"     Display="true" />
                                                <telerik:GridBoundColumn UniqueName="CREDIT_ATTEMPTED"      DataField="CREDIT_ATTEMPTED"    SortExpression="CREDIT_ATTEMPTED"   HeaderText="CREDIT_ATTEMPTED"   Display="true" />
                                                <telerik:GridBoundColumn UniqueName="CREDIT_EARNED"         DataField="CREDIT_EARNED"       SortExpression="CREDIT_EARNED"      HeaderText="CREDIT_EARNED"      Display="true" />
                                                <telerik:GridBoundColumn UniqueName="COURSE_MARK_EFFORT"    DataField="COURSE_MARK_EFFORT"  SortExpression="COURSE_MARK_EFFORT" HeaderText="COURSE_MARK_EFFORT" Display="true" />
                                                <telerik:GridBoundColumn UniqueName="COURSE_MARK"           DataField="COURSE_MARK"         SortExpression="COURSE_MARK"        HeaderText="COURSE_MARK"        Display="false" />
                                                <telerik:GridBoundColumn UniqueName="EFFORT_DESCRIPTOR"     DataField="EFFORT_DESCRIPTOR"   SortExpression="EFFORT_DESCRIPTOR"  HeaderText="EFFORT_DESCRIPTOR"  Display="false" />
                                            </Columns>
                                        </telerik:GridTableView>
                                    </DetailTables>
                                    <Columns>
                                        <telerik:GridBoundColumn DataField="SCHOOL_YEAR"                UniqueName="SCHOOL_YEAR"                SortExpression="SCHOOL_YEAR"                HeaderText="SCHOOL_YEAR"                Display="true" />
                                        <telerik:GridBoundColumn DataField="GRADE_LEVEL_CODE"           UniqueName="GRADE_LEVEL_CODE"           SortExpression="GRADE_LEVEL_CODE"           HeaderText="GRADE_LEVEL_CODE"           Display="true" />
                                        <telerik:GridBoundColumn DataField="SEMESTER_TERM"              UniqueName="SEMESTER_TERM"              SortExpression="SEMESTER_TERM"              HeaderText="SEMESTER_TERM"              Display="false" />
                                        <telerik:GridBoundColumn DataField="SEMESTER_TERM_Nm"           UniqueName="SEMESTER_TERM_Nm"           SortExpression="SEMESTER_TERM_Nm"           HeaderText="SEMESTER_TERM_Nm"           Display="true" />
                                        <telerik:GridBoundColumn DataField="ATTENDING_DISTRICT_ID_Nm"   UniqueName="ATTENDING_DISTRICT_ID_Nm"   SortExpression="ATTENDING_DISTRICT_ID_Nm"   HeaderText="ATTENDING_DISTRICT_ID_Nm"   Display="true" />
                                        <telerik:GridBoundColumn DataField="ATTENDING_SCHOOL_ID_Nm"     UniqueName="ATTENDING_SCHOOL_ID_Nm"     SortExpression="ATTENDING_SCHOOL_ID_Nm"     HeaderText="ATTENDING_SCHOOL_ID_Nm"     Display="true" />
                                    </Columns>
                                </MasterTableView>
                            </telerik:RadGrid>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblNoData" runat="server" Text="No Data Available" Visible="false" />
                        </td>
                    </tr>
                </table>
     
                <asp:HiddenField ID="hdnLoadDone" runat="server" Value="" />
     
            </form>
        </body>
    </html>
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Jun 2012 Link to this post

    Hi,

    I could replicate the issue when i set the AllowCustomSorting property to true in the GridTableView.With custom sorting turned on, RadGrid will display as Sorting Icons, will maintain the SortExpressions collection and so on, but it will not actually sort the Data. You should perform the custom sorting in the SortCommand event handler.Please try setting the AllowCustomSorting property to false if you don't want to customize sorting.

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. <span>w</span>
    <span>w</span> avatar
    84 posts
    Member since:
    Jun 2012

    Posted 17 Jan 2013 Link to this post

    avatarHi

    My RadGrid sorting does not work properly. I figure out that why its not working properly. I need its solution. Let me explain.

     public partial class TestPage: ParentClass  // System.Web.UI.Page
     {
     }

    I inherit My ParentClass instead of System.Web.UI.Page. So RadGrid not working properly. I have some session mgt in ParentClass.
    and My ParentClass is inherit from System.Web.UI.Page. But when i click on RadGrid sorting its does not properly. It sort only one time and some time i click on one column it sort other column.

    Can you have any solution that why its happening?

    If i did not inherit it from ParentClass and inherit it from System.Web.UI.Page . its work great.
    Thanks,
    Muhammad Waseem
    the Telerik team
Back to Top