THESE FORUMS ARE NOW FROZEN
Please choose "Forums" from the Main menu of www.entityspaces.net to get to our new forums.

Paging and Sorting on Sql 2000 using esDataSource

rated by 0 users
This post has 4 Replies | 1 Follower

Top 200 Contributor
Posts 13
cvintila Posted: 08-17-2007 5:01 PM

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
 

Top 10 Contributor
Posts 905
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 | Blog | Twitter

Top 200 Contributor
Posts 13

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

Top 10 Contributor
Posts 905
Thats really what you will have to do on 2000 as you must handle it yourself, good job....

Regards, Scott Schecter EntitySpaces | Blog | Twitter

Page 1 of 1 (5 items) | RSS
Copyright © 2005 - 2009, EntitySpaces, LLC