R
Richard McClelland
I created a DataGrid that allows sorting by several columns. However,
if the DataGrid spans more than one page, when I navigate to the next
page the Data is not sorted. Below is PageIndexChanged and
SortCommand methods. Any help would be much appreciated.
private void ActivationsList_PageIndexChanged_1(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
ActivationsList.CurrentPageIndex = e.NewPageIndex;
//Get DataTable of current Session
DataTable dt = new DataTable();
dt = (DataTable)Session["Source"];
// Create a DataView from the DataTable.
DataView dv = new DataView(dt);
// Re-bind the data to refresh the DataGrid control.
ActivationsList.DataSource = dv;
ActivationsList.DataBind();
}
private void ActivationsList_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
// Retrieve the data source from session state.
ActivationsList.CurrentPageIndex = 0;
DataTable dt = new DataTable();
dt = (DataTable)Session["Source"];
// Create a DataView from the DataTable.
DataView dv = new DataView(dt);
// The DataView provides an easy way to sort. Simply set the
// Sort property with the name of the field to sort by.
dv.Sort = e.SortExpression;
// Rebind the data source and specify that it should be sorted
// by the field specified in the SortExpression property.
ActivationsList.DataSource = dv;
ActivationsList.DataBind();
if the DataGrid spans more than one page, when I navigate to the next
page the Data is not sorted. Below is PageIndexChanged and
SortCommand methods. Any help would be much appreciated.
private void ActivationsList_PageIndexChanged_1(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
ActivationsList.CurrentPageIndex = e.NewPageIndex;
//Get DataTable of current Session
DataTable dt = new DataTable();
dt = (DataTable)Session["Source"];
// Create a DataView from the DataTable.
DataView dv = new DataView(dt);
// Re-bind the data to refresh the DataGrid control.
ActivationsList.DataSource = dv;
ActivationsList.DataBind();
}
private void ActivationsList_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
// Retrieve the data source from session state.
ActivationsList.CurrentPageIndex = 0;
DataTable dt = new DataTable();
dt = (DataTable)Session["Source"];
// Create a DataView from the DataTable.
DataView dv = new DataView(dt);
// The DataView provides an easy way to sort. Simply set the
// Sort property with the name of the field to sort by.
dv.Sort = e.SortExpression;
// Rebind the data source and specify that it should be sorted
// by the field specified in the SortExpression property.
ActivationsList.DataSource = dv;
ActivationsList.DataBind();