Hi,
I am encountering issues with my grid after I perform a sort.
I have a web page that binds a <List> of objects to my datagrid in the page load. I also store this list in the users session for later use when I want to perform selecting.
List<Invoice> outstandingInvoices = InvoiceInfo.GetOutstandingInvoicesByDebtor(1);
Session["outstandingInvoices"] = outstandingInvoices;
rg_Invoices.DataSource = outstandingInvoices;
After the user has select items in rg_Invoices they click a select button and the invoices they selected placed in rg_Assigned and Removed from rg_Invoices
//create a list to store what was selected
List<InvoiceInfo> assignedInvoices = (List<InvoiceInfo>)Session["assignedInvoices"];
//read in the original list from the session
List<InvoiceInfo> outstandingInvoices = (List<InvoiceInfo>)Session["outstandingInvoices"];
//Create a new outstandingInvoicesList
List<InvoiceInfo> newOutstandingInvoices = new List<InvoiceInfo>();
foreach (InvoiceInfo inv in outstandingInvoices)
{
bool test = false;
//compare it against the selected items in the grid
foreach (GridDataItem item in rg_Invoices.SelectedItems)
{
InvoiceInfo invoice = (InvoiceInfo)outstandingInvoices[item.ItemIndex];
if (inv == invoice)
{
//if it finds it then add the obj to assigned
assignedInvoices.Add(invoice);
test = true;
}
}
if (!test)
newOutstandingInvoices.Add(inv); //if not found add to new matches
}
Session["assignedInvoices"] = assignedInvoices;
rg_Assigned.DataSource = assignedInvoices;
rg_Assigned.DataBind();
Session["outstandingInvoices"] = newOutstandingInvoices;
rg_Invoices.DataSource = newOutstandingInvoices;
rg_Invoices.DataBind();
This all works fine however if I perform a sort on the grid and then try so select items from rg_Invoices into rg_Assigned then the wrong invoice gets brought across.
My code to sort the datagrid is
protected void rg_Invoices_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
List<InvoiceInfo> outstandingInvoices = (List<InvoiceInfo>)Session["outstandingInvoices"];
rg_Invoices.DataSource = outstandingInvoices;
}
The sort works fine but it appears that the sort only works client side and the list of invoices in my session does not get sorted therefore they then become out of synch when I try to select.
Is there any way that I can set my session to the sorted format in the NeedDataSource method??
Any help would be greatly appreciated.
Thanks,
Michael
I am encountering issues with my grid after I perform a sort.
I have a web page that binds a <List> of objects to my datagrid in the page load. I also store this list in the users session for later use when I want to perform selecting.
List<Invoice> outstandingInvoices = InvoiceInfo.GetOutstandingInvoicesByDebtor(1);
Session["outstandingInvoices"] = outstandingInvoices;
rg_Invoices.DataSource = outstandingInvoices;
After the user has select items in rg_Invoices they click a select button and the invoices they selected placed in rg_Assigned and Removed from rg_Invoices
//create a list to store what was selected
List<InvoiceInfo> assignedInvoices = (List<InvoiceInfo>)Session["assignedInvoices"];
//read in the original list from the session
List<InvoiceInfo> outstandingInvoices = (List<InvoiceInfo>)Session["outstandingInvoices"];
//Create a new outstandingInvoicesList
List<InvoiceInfo> newOutstandingInvoices = new List<InvoiceInfo>();
foreach (InvoiceInfo inv in outstandingInvoices)
{
bool test = false;
//compare it against the selected items in the grid
foreach (GridDataItem item in rg_Invoices.SelectedItems)
{
InvoiceInfo invoice = (InvoiceInfo)outstandingInvoices[item.ItemIndex];
if (inv == invoice)
{
//if it finds it then add the obj to assigned
assignedInvoices.Add(invoice);
test = true;
}
}
if (!test)
newOutstandingInvoices.Add(inv); //if not found add to new matches
}
Session["assignedInvoices"] = assignedInvoices;
rg_Assigned.DataSource = assignedInvoices;
rg_Assigned.DataBind();
Session["outstandingInvoices"] = newOutstandingInvoices;
rg_Invoices.DataSource = newOutstandingInvoices;
rg_Invoices.DataBind();
This all works fine however if I perform a sort on the grid and then try so select items from rg_Invoices into rg_Assigned then the wrong invoice gets brought across.
My code to sort the datagrid is
protected void rg_Invoices_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
List<InvoiceInfo> outstandingInvoices = (List<InvoiceInfo>)Session["outstandingInvoices"];
rg_Invoices.DataSource = outstandingInvoices;
}
The sort works fine but it appears that the sort only works client side and the list of invoices in my session does not get sorted therefore they then become out of synch when I try to select.
Is there any way that I can set my session to the sorted format in the NeedDataSource method??
Any help would be greatly appreciated.
Thanks,
Michael