Begin in Edit Mode/Template on most recently added row.

10 posts, 1 answers
  1. Richard
    Richard avatar
    27 posts
    Member since:
    Sep 2008

    Posted 21 Sep 2009 Link to this post

    Hi,

    I'm successfully using Drag-Drop between a tree and a grid based on this example:
    http://demos.telerik.com/aspnet-ajax/treeview/examples/functionality/draganddropnodes/defaultcs.aspx

    However, I can't get the most recently added (dropped-on-grid) row to immediately open into Edit mode. The "edit" button works fine on the row and opens the EditItem template without problems, but I want the newly added row to initially appear in this edit mode. I've tried many methods: OnDataBound -- no go, OnDataBinding -- no go, OnItemCreated -- works fine, buts get called for each of the newly added items, and since I am updating the RadGrid each time from a DataTable, ALL of the items are newly created each time (just like in the example). So, any tips on how to force the most recently entered (newest, last-in-table) row to open into edit mode when added? I don't care whether it is client or server side (or mixture) code.

    Thanks for any tips!
    R
  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 24 Sep 2009 Link to this post

    Hi Richard,

    When performing the drop operation on the server (i.e. at the point at which you are adding the new rows to the grid) you should remember the primary key values of the new rows in an array. When the grid is rebound, in the ItemCreated event just check if the current item's data key value is contained in the array of primary keys and if so, put the item in edit mode.

    I hope this helps.

    Regards,
    Tsvetoslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Richard
    Richard avatar
    27 posts
    Member since:
    Sep 2008

    Posted 24 Sep 2009 Link to this post

    Thanks Tsvetoslav,

    This would be ok, except I tried the OnItemCreated event (see my post), and the way I see it, it gets called for every single Item in the table -- logically -- but this is not acceptable from the perspective of network/performance: to have N-Row additional calls back to the server, just to set one single row in Edit mode. Is there a better way. A way to handle it Client-Side? If your read the doc, it looks like the property "Item.Edit = true" should also be settable server-side in the DataBound callback.

    Anyway, ideas or tips appreciated! I can imagine a javascript hack for it, but I'd prefer not to if there is a better way.

    Thanks,
    R


  5. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 25 Sep 2009 Link to this post

    Hi Richard,

    The ItemCreated event is thrown each time the grid is rebound and you do need to rebind the grid when the new rows are dropped unto it so that the control is correctly populated with the new records. So, the ItemCreated event will be thrown in any case given your scenario and if so, you can use it without any remorse to put the new rows in EditMode.

    Regards,
    Tsvetoslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 25 Sep 2009 Link to this post

    Hi Richard,

    The ItemCreated event is thrown each time the grid is rebound and you do need to rebind the grid when the new rows are dropped unto it so that the control is correctly populated with the new records. So, the ItemCreated event will be thrown in any case given your scenario and if so, you can use it without any remorse to put the new rows in EditMode.

    Regards,
    Tsvetoslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Richard
    Richard avatar
    27 posts
    Member since:
    Sep 2008

    Posted 25 Sep 2009 Link to this post

    Hi Tsvetoslav,

    Thanks, but there is still a misunderstanding here. If I don't register a callback, it won't be called. So if I don't register ItemCreated then I don't get a server-call for each single row I put into the grid -- at least I'm not seeing it, and I certainly hope this is true. If you are referring to something else, or a client-side callback, then please be specific as to which callback you are referring to. I tested the ItemCreated... what I need is either a client-side event, or a SINGLE server side callback, or, at best (and as your documentations suggests) just set the Items[last-item-index].Edit = true in OnDataBound.

    Thanks!
    Richard
  8. Answer
    Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 26 Sep 2009 Link to this post

    Hi Richard,

    You are correct - if you do not register a call-back, it won't be called. However, I'd like to turn your attention to the following points:

    1. The overhead in performance for registering an event handler for the ItemCreated event will be so negligible that it will be barely caught (if at all) by code profiling tools.

    2. There is no other event that can be used for putting grid rows in edit mode without rebinding the grid. You can certainly use DataBound, PreRender etc., but after setting the items' Edit property to true you should call the grid's Rebind() method - and this is bound to incur much more overhead than the previous approach.

    3. Furthermore, please, take into consideration that the ItemCreated-event approach won't work for the Inline edit mode of the grid. Therefore, if you intend to use Inline edit mode, you should use the grid's DataBound event, put the newly dropped items in Edit mode and rebind the grid.

    I hope this information will prove helpful.

    Regards,
    Tsvetoslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Richard
    Richard avatar
    27 posts
    Member since:
    Sep 2008

    Posted 26 Sep 2009 Link to this post

    Thank you Tsvetoslav,

    this is certainly an adequate and helpful explanation and, as such, marked as the answer. What I'm still doubting, is that an ItemCreated event that incurs a network callback for each row is negligible, especially if I have a grid with 1000 rows (which I don't, but...) : that would be 1000 network calls with JSON marshalling on both sides, certainly not negligible. I don't even like the fact that I will have 5 to 10 network calls in my small drag-and drop case... but if it's the only way (baring a js hack) then that is that.

    Best regard!
    Richard
  10. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 28 Sep 2009 Link to this post

    Hello Richard,

    I think there is some misunderstanding on you part concerning the event handlers wired up to the ItemCreated event of the grid. Please, note that there are no network callbacks performed when any event handler attached to any event of the grid is called. Concerning the ItemCreated event in particular it constitutes a list of function pointers (what an event in .NET really is) and the methods attached to this list get called each time a grid row is created. This creation of the rows and consequently the calling of the event handlers is performed on the server and within the bounds of one single request to it - there are no round trips from the client to the server and back for each call to the ItemCreated event handlers.

    Best Regards,
    Tsvetoslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. Richard
    Richard avatar
    27 posts
    Member since:
    Sep 2008

    Posted 28 Sep 2009 Link to this post

    Hi Tsvetoslav, Ok, I'll take a look and see what I've got wrong in the protocol. Thanks for the support.
    R
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017