locked
GridView inline Editing (ListDetails.aspx) - pressing Enter key cancels the edit RRS feed

  • Question

  • User-1336852631 posted

    I have a Dynamic Data project and have edited the Global.asax.cs file to allowing combined page mode:

                // The following statements support combined-page mode, where the List, Detail, Insert, and
                // Update tasks are performed by using the same page. To enable this mode, uncomment the
                // following routes and comment out the route definition in the separate-page mode section above.
                routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
                {
                    Action = PageAction.List,
                    ViewName = "ListDetails",
                    Model = DefaultModel
                });
    
                routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
                {
                    Action = PageAction.Details,
                    ViewName = "ListDetails",
                    Model = DefaultModel
                });

    After pressing Edit in a ListDetails page to edit a GridView row, you can edit the fields in the row and press Update to commit the changes. However if during typing you press the Enter key on the keyboard, the changes to the row are cancelled.

    Does anyone know of anyway to change this behaviour to submit the changes, rather than cancelling (or at least prevent the cancel)?

    I've search around and found people have used javascript on the client side to trap the enter key, e.g. in a GridView RowEditing event:

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
    GridView gv = (GridView)sender;
    int rowIndex = e.NewEditIndex; //AutoGenerateEditButton / CommandName="Edit"
    GridViewRow row = gv.Rows[rowIndex];
    int id = Convert.ToInt32(gv.DataKeys[rowIndex][0]);
    
    row.Attributes.Add("onkeypress", "javascript:if (event.keyCode == 13) { __doPostBack('" + gv.UniqueID + "', 'Update$" + row.RowIndex.ToString() + "'); return false; }");
    }

    However this doesn't work

    Monday, June 25, 2012 7:32 AM

Answers

  • User-330204900 posted

    Sorry Biga, at the moment UpdatableList does not work with Domain Service dues to some issues with DomainService data source, I think I have a way around it but I am trying to find out if there is any future in Domain Service as I can't see a project templte for eith DS or Linq to SQL in VS2012.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 6, 2012 6:09 AM
  • User-330204900 posted

    yes it woudl but there are new things comming in 4.5 such as model binding which may make this not a problem, and I don't think DS will go a way soon I just don't see any more development inverment.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 9, 2012 4:14 AM

All replies

  • User-330204900 posted

    Hi Biga, I do have a custom page template that allows inline Edit and Insert send me an e-mail and I will send you a sample :)

    Monday, June 25, 2012 9:31 AM
  • User3866881 posted

    biga

    Member

    How's everything going with you?Anyfeedback is welcomed……

    Saturday, June 30, 2012 9:43 PM
  • User-1336852631 posted

    Hi Steve,

    Sorry for the delay in responding.  I was diverted onto something else for a while.

    I tried the UpdateableList page template you kindly sent me and while I do prefer the way you insert records (inline in the grid), I had a couple of problems, that means I will need to go back to using ListDetails for the time being until I have time to look again at this:

    1.  I'm using DomainService and while I could edit the code you sent to work with DomainService I get Domain Exceptions when editing records which relate to entity that have restricted access for the user.

    2. The UpdateableList page template doesn't really solve the problem I created this thread for.  It is improved in that when you press enter while editing an inline field, it doesn't cancel the entire row edit operation (which happens when I use the ListDetails page template), it does clear the field being edited.

    Thanks again for all your help.

    Wednesday, July 4, 2012 11:28 AM
  • User-330204900 posted

    Sorry Biga, at the moment UpdatableList does not work with Domain Service dues to some issues with DomainService data source, I think I have a way around it but I am trying to find out if there is any future in Domain Service as I can't see a project templte for eith DS or Linq to SQL in VS2012.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 6, 2012 6:09 AM
  • User-1336852631 posted
    It would be a shame if DomainService is dropped as its really cool, especially for controlling access at the row level..
    Friday, July 6, 2012 3:35 PM
  • User-330204900 posted

    yes it woudl but there are new things comming in 4.5 such as model binding which may make this not a problem, and I don't think DS will go a way soon I just don't see any more development inverment.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 9, 2012 4:14 AM