locked
Display sorting criteria in the header RRS feed

  • Question

  • User1863216143 posted

    Hi All,

    Do you know of any way to display in the header the sorting criteria the user has selected? Can that be accessed programatically?

    For example, if I have Column1, Column2, ... Column9 and the user multiselects Column2 and Column5, ideally I'd like to display "Sorted by Column2 descending and Column5 ascending". If this is not possible, is there a way to highlight which columns were used for sorting?

    Regards,

    Andrew

    Monday, October 31, 2011 12:31 AM

Answers

  • User500621135 posted

    hello sir,

    yes,By using the that Column id 

    we can highlight that column 

    private string ConvertSortDirectionToSql(SortDirection sortDireciton)<o:p></o:p>

        {<o:p></o:p>

            string m_SortDirection = String.Empty;<o:p></o:p>

    <o:p> </o:p>

            switch (m_SortDirection)<o:p></o:p>

            {<o:p></o:p>

                case SortDirection.Ascending:<o:p></o:p>

                    m_SortDirection = "ASC";<o:p></o:p>

                    break;<o:p></o:p>

    <o:p> </o:p>

                case SortDirection.Descending:<o:p></o:p>

                    m_SortDirection = "DESC";<o:p></o:p>

                    break;<o:p></o:p>

            }<o:p></o:p>

    <o:p> </o:p>

            return m_SortDirection();<o:p></o:p>

        }<o:p></o:p>

    <o:p> </o:p>

        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)<o:p></o:p>

        {<o:p></o:p>

            DataTable m_DataTable = GridView1.DataSource as DataTable;<o:p></o:p>

    <o:p> </o:p>

            if (m_DataTable != null)<o:p></o:p>

            {<o:p></o:p>

                DataView m_DataView = new DataView(m_DataTable);<o:p></o:p>

                m_DataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);<o:p></o:p>

    <o:p> </o:p>

                GridView1.DataSource = m_DataView;<o:p></o:p>

                GridView1.DataBind();<o:p></o:p>

            }<o:p></o:p>

        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 31, 2011 1:58 AM

All replies

  • User500621135 posted

    hello sir,

    yes,By using the that Column id 

    we can highlight that column 

    private string ConvertSortDirectionToSql(SortDirection sortDireciton)<o:p></o:p>

        {<o:p></o:p>

            string m_SortDirection = String.Empty;<o:p></o:p>

    <o:p> </o:p>

            switch (m_SortDirection)<o:p></o:p>

            {<o:p></o:p>

                case SortDirection.Ascending:<o:p></o:p>

                    m_SortDirection = "ASC";<o:p></o:p>

                    break;<o:p></o:p>

    <o:p> </o:p>

                case SortDirection.Descending:<o:p></o:p>

                    m_SortDirection = "DESC";<o:p></o:p>

                    break;<o:p></o:p>

            }<o:p></o:p>

    <o:p> </o:p>

            return m_SortDirection();<o:p></o:p>

        }<o:p></o:p>

    <o:p> </o:p>

        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)<o:p></o:p>

        {<o:p></o:p>

            DataTable m_DataTable = GridView1.DataSource as DataTable;<o:p></o:p>

    <o:p> </o:p>

            if (m_DataTable != null)<o:p></o:p>

            {<o:p></o:p>

                DataView m_DataView = new DataView(m_DataTable);<o:p></o:p>

                m_DataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);<o:p></o:p>

    <o:p> </o:p>

                GridView1.DataSource = m_DataView;<o:p></o:p>

                GridView1.DataBind();<o:p></o:p>

            }<o:p></o:p>

        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 31, 2011 1:58 AM
  • User1863216143 posted

    Hi Kamal, 

    Thanks for the answer. Does this solution (or a similar one) apply within SSRS?

    Regards,

    Andres

    Monday, October 31, 2011 4:04 AM
  • User500621135 posted

    yes,

    It works on SSRS

    Monday, October 31, 2011 6:33 AM
  • User-8475372 posted

    Androcles, 

    Right click on the column and select Properties --> Interactive Sorting -- > Sort By <Criteria>

    By default, the sorted column highlights itself with an arrow facing the direction of the sort. 

    Wednesday, November 2, 2011 7:29 AM