The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Paging and Sorting on Sql 2000 using esDataSource

Last post 08-18-2007, 6:30 AM by Scott.Schecter. 4 replies.
Sort Posts: Previous Next
  •  08-17-2007, 5:01 PM 4602

    Paging and Sorting on Sql 2000 using esDataSource

    Hi guys,

     Let me start by saying that this product is awesome. Love the new esdatasource control. I know about the paging and sorting issue with Sql 2005.

    Scott.Schecter:
    You have to set the properties AutoSorting="False" AutoPaging="False" on your esDataSource control. You then have to roll your own sorting and paging if you require them. The must also now call your .Load() explicitly in your esSelectEvent.

     
    Do you have any examples on how to best implement sorting and paging using es code and syntax.

     
    Thanks for your help.

     

    Cristian
     

  •  08-17-2007, 5:12 PM 4603 in reply to 4602

    Re: Paging and Sorting on Sql 2000 using esDataSource

    AutoSorting and AutoPaging are available only on Sql 2005 as this is when MIcrosoft added the new syntax to do so. On Sql 2000 you will have to implement this yourself.

    Regards,

    Scott Schecter
    EntitySpaces | My Site
  •  08-17-2007, 5:15 PM 4604 in reply to 4603

    Re: Paging and Sorting on Sql 2000 using esDataSource

  •  08-17-2007, 8:39 PM 4607 in reply to 4604

    Re: Paging and Sorting on Sql 2000 using esDataSource

    Hi Scott, Thanks for the samples, i have seen those before, it helped me quite a bit to get the rest of the functionality working. Right now, i'm looking at implementing some proper paging and sorting for sql 2000.

    This is the code i was working with before but i really like the es way of coding and i'm still getting used to it.

    Code:
    public partial class cust_search : System.Web.UI.Page
    {

    private string GridViewSortDirection
    {
    get { return ViewState["SortDirection"] as string ?? "ASC"; }
    set { ViewState["SortDirection"] = value; }
    }

    private string GridViewSortExpression
    {
    get { return ViewState["SortExpression"] as string ?? string.Empty; }
    set { ViewState["SortExpression"] = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    DataTable BindData(string searchType, string whereClause, string searchCriteria)
    {
    ContactsCollection cc = new ContactsCollection();
    //custom method in BLL DataTable newDt = cc.searchContact("customer", searchCriteria, searchType, whereClause);

    ViewState["gvResults_DataSource"] = newDt;

    return newDt;
    }

    protected void searchGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
    searchGrid.DataSource = SortDataTable((DataTable)ViewState["gvResults_DataSource"], true);
    searchGrid.PageIndex = e.NewPageIndex;
    searchGrid.DataBind();
    }

    protected void searchGrid_Sorting(object sender, GridViewSortEventArgs e)
    {
    GridViewSortExpression = e.SortExpression;

    int pageIndex = searchGrid.PageIndex;

    searchGrid.DataSource = SortDataTable((DataTable)ViewState["gvResults_DataSource"], false);
    searchGrid.DataBind();

    searchGrid.PageIndex = pageIndex;
    }

    private string GetSortDirection()
    {
    switch (GridViewSortDirection)
    {
    case "ASC":
    GridViewSortDirection = "DESC";
    break;
    case "DESC":
    GridViewSortDirection = "ASC";
    break;
    }
    return GridViewSortDirection;
    }

    protected DataView SortDataTable(DataTable dataTable, bool isPageIndexChanging)
    {
    if (dataTable != null)
    {
    DataView dataView = new DataView(dataTable);
    if (GridViewSortExpression != string.Empty)
    {
    if (isPageIndexChanging)
    {
    dataView.Sort = string.Format("{0} {1}", GridViewSortExpression, GridViewSortDirection);
    }
    else { dataView.Sort = string.Format("{0} {1}", GridViewSortExpression, GetSortDirection());
    }
    }
    return dataView;
    }
    else { return new DataView();
    }
    }
    }



    As you can see, it's quite an involved way of doing it and i was wondering if you got a better way using ES.

    Thanks for all your help.

    Cristian

  •  08-18-2007, 6:30 AM 4609 in reply to 4607

    Re: Paging and Sorting on Sql 2000 using esDataSource

    Thats really what you will have to do on 2000 as you must handle it yourself, good job....

    Regards,

    Scott Schecter
    EntitySpaces | My Site
View as RSS news feed in XML