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