I am manually binding an ASP.NET ListView to an array of objects sorted alphabetically by name. After editing an item, the DataSource is set again and DataBind is called. If the name changed, the item you just edited may have moved, potentially to another page even.
For example; you just renamed Hot Dog to Sausage, so Sausage moved after ItemUpdating completes.
--- OLD LIST --- --- NEW LIST ---
Hamburger Hamburger
Hot Dog______ Pizza
Pizza |_____Sausage
Is this behavior you would expect from a form? When you edit a row, should you expect to see that row after saving it? Should it be in the exact same position? Should I display only the record you just edited after saving?
As for the technical side of maintaining the previous order after saving, and potentially changing the order;
I know why this is happening. I’m looking for ideas of avoiding it.
I’m thinking about dropping both combining the controls of EditItemTemplate into ItemTemplate and setting visibility on read-only / editable controls based on the ListView EditIndex.
This seems feasible but I’m wondering if you fine folks have any other ideas.
The behavior that you are seeing here is the typical desired output as once you make the change the information is properly sorted. If you have a need to keep the old structure you are most likely going to have to go a route similar to what you mentioned in your post.
However, I would take a second and see if this is really what your users are going to want, I could see this getting really confusing after a large number of edits.