I’ve got a ListView and a DetailsView component on the same .ASPX page. The DetailsView displays aggregate totals for the rows shown in the ListView. To keep it up to date, I call DetailsView.DataBind() in ListView ItemUpdated, ItemInserted and ItemDeleted event handlers.
When ENTER is pressed in a field while editing or inserting, changes to the current row are undone and the first visible row is put in edit mode. If I click the Update button instead of pressing ENTER, it works as expected.
I originally assumed that this behavior was just the status quo, as it occurred before I added the DataBind calls, however I noticed by accident that if the Update button was first in the row, and the cancel button was last, pressing ENTER behaved as I wanted — it saved the changes to the current row and exited edit mode. But that’s ONLY true if my DataBind calls are not in place.
I suppose I could add a refresh button for the DetailsView, but I really can’t decide which is uglier, that or having to remember to not press ENTER.
Any ideas on how to make this thing behave?
TIA,
MM
The problem was that pressing ENTER ‘clicks’ the first button that occurs on the form. So I created a button above the other controls with a transparent image, and the following click handler:
Maybe not the most elegant solution in the universe, but seems to work, and surely beats all hell out of the way it behaves by default. Maybe if I hadn’t have used ImageButtons this wouldn’t have been necessary, but the functions save, edit, delete, undo and insert are sooo easily represented by 16×16 images, the text equivilents are a waste of horizontal space.
In any case, I’ll take it. 🙂