locked
Sort Rows according to OrderID Column RRS feed

  • Question

  • User-511529073 posted

    i have table called "Brand" have the following columns (ID, Name, Website, OrderID)

    i have generated Admin Website using Dynamic Data, I need to sort the rows that displayed at "List" Page of Brands according to Brand OrderID value.

    how can i do that using Dyanmic Data ?

    thanks,

    Sunday, July 31, 2011 9:05 AM

Answers

  • User-330204900 posted

    Hi reda_sondos, try this

    /// <summary>
    /// Sets the initial sort order.
    /// </summary>
    /// <param name="queryExtender">The query extender.</param>
    /// <param name="table">The table.</param>
    public static void SetInitialSortOrder(this QueryExtender queryExtender, MetaTable table)
    {
        // set default sort
        if (table.SortColumn != null)
        {
            var order = new OrderByExpression()
            {
                DataField = table.SortColumn.Name,
                Direction = table.SortDescending ? SortDirection.Descending : SortDirection.Ascending,
            };
            queryExtender.Expressions.Add(order);
        }
    }

    This is an extension method to use it simply call from List page lise so

    // set initial sort order
    GridQueryExtender.SetInitialSortOrder(table);
    
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 1, 2011 6:07 AM

All replies

  • User-20777992 posted

    If you want to sort gridview on multiple columns then this is how you can do -

    In Page Template\List.aspx.cs & in Page_Laod event check for table name

    if (!Page.IsPostBack) {
    if (table.Name == "Project")
    {

    GridView1.Sort("ClientDetail.CompanyName asc,ProjectName asc", SortDirection.Ascending);

    }

    }

    and you can also provide order either ascending or descending for each column.

    Sunday, July 31, 2011 2:56 PM
  • User-526354650 posted

    In a dynamic data application, you can use the DisplayColumnAttribute to change the default sort order for a table.

    [DisplayColumn("Name", "OrderID")]
    partial class Brand
    {
    
    }
    Sunday, July 31, 2011 3:16 PM
  • User1219881809 posted

    i have table called "Brand" have the following columns (ID, Name, Website, OrderID)

    i have generated Admin Website using Dynamic Data, I need to sort the rows that displayed at "List" Page of Brands according to Brand OrderID value.

    You can sort by the time to show dataSource (I suppose DataTable is the datasource) .

            DataTable _dt = new DataTable();
            _dt.DefaultView.Sort = "OrderID desc";
            GridView1.DataSource = _dt;

    After showing the datasource.

    GrdDynamic.Sort("OrderID", SortDirection.Ascending);

    Regards.

    Monday, August 1, 2011 5:59 AM
  • User-330204900 posted

    Hi reda_sondos, try this

    /// <summary>
    /// Sets the initial sort order.
    /// </summary>
    /// <param name="queryExtender">The query extender.</param>
    /// <param name="table">The table.</param>
    public static void SetInitialSortOrder(this QueryExtender queryExtender, MetaTable table)
    {
        // set default sort
        if (table.SortColumn != null)
        {
            var order = new OrderByExpression()
            {
                DataField = table.SortColumn.Name,
                Direction = table.SortDescending ? SortDirection.Descending : SortDirection.Ascending,
            };
            queryExtender.Expressions.Add(order);
        }
    }

    This is an extension method to use it simply call from List page lise so

    // set initial sort order
    GridQueryExtender.SetInitialSortOrder(table);
    
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 1, 2011 6:07 AM