Radgrid in edit mode appears in the first row

4 posts, 0 answers
  1. Samuel
    Samuel avatar
    3 posts
    Member since:
    Jan 2012

    Posted 04 Sep 2018 Link to this post

    I have a radgrid with an ASCX in edit mode I cancel the default operation, to pass some initial values to the control. But the ASCX appears in the first fial as if it were in insert.

    else if (e.CommandName == "Edit")
            {
                GridEditableItem item = (GridEditableItem)e.Item;
     
                e.Item.OwnerTableView.ClearEditItems();
                e.Canceled = true;
     
                System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
                newValues["IdHotel"] = VALUE
                newValues["IdPaqueteHotelDetalle"] = VALUE
     
                e.Item.OwnerTableView.InsertItem(newValues);
                e.Item.OwnerTableView.IsItemInserted = false;
                e.Item.OwnerTableView.EditFormSettings.UserControlName = "Controles/PaqueteHotelDetalle.ascx";
            }
  2. Tsvetomir
    Admin
    Tsvetomir avatar
    196 posts

    Posted 07 Sep 2018 Link to this post

    Hi Samuel,

    If you want to execute different logic for the Edit mode and for the Insert mode, you do it in the ItemCreated or in the ItemDataBound events. Then you can modify the edit form appearance(on ItemCreated) or edit form controls values (on ItemDataBound) if needed. You can find more information here: Distinguish Edit or Insert Mode.

    I am also attaching a sample project, to which you can refer to gain more insight on the different Edit form types. In order to flawlessly run the example, you will have to create a Bin folder and include the Telerik dlls in there. If an issue related to the database occur, you will have to customize and configure the connection string in the web.config file.

    Furthermore, it would be ideal if you could explain your scenario in more details, which will enable us to give more accurate answers and create a project to reflect your exact requirements.

    Kind regards,
    Tsvetomir
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Samuel
    Samuel avatar
    3 posts
    Member since:
    Jan 2012

    Posted 07 Sep 2018 in reply to Tsvetomir Link to this post

    Hi Tsvetomir, thanks for replying, I will review the attached project. Meanwhile, I comment with more details what I want. I have a radgrid with some columns in it, to insert and edit I use an ASCX, but inside ASCX I have other controls that are populated with DataObject, but to initialize them I need parameters that I send them from the events: e.CommandName == "InitInsert" and e.CommandName == "Edit" by them is that I must cancel the default operation (e.Canceled = true;) to insert values in the IDictionary everything works fine, the only drawback is that when editing some row, the ASCX appears in the upper part as if I were inserting and not in the same row that I am editing, I understand that this happens because I cancel the default operation in the edit command (e.Canceled = true;) I have been looking for some solution but I still can not get it , let's say that the problem I have is just visualization.

    if (e.CommandName == "InitInsert")
            {
                e.Item.OwnerTableView.ClearEditItems();
                e.Canceled = true;
     
                System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
                newValues["IdHotel"] = VALUE FROM PARENT
                e.Item.OwnerTableView.InsertItem(newValues);
            }
     
            else if (e.CommandName == "Edit")
            {
                GridEditableItem item = (GridEditableItem)e.Item;
                e.Item.OwnerTableView.ClearEditItems();
                e.Canceled = true;
     
                System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
                newValues["IdHotel"] = VALUE FROM PARENT
                newValues["IdPaqueteHotelDetalle"] = VALUE FROM PARENT
     
                e.Item.OwnerTableView.InsertItem(newValues);
                e.Item.OwnerTableView.IsItemInserted = false;
                e.Item.OwnerTableView.EditFormSettings.UserControlName = "Controles/PaqueteHotelDetalle.ascx";
            }
  4. Tsvetomir
    Admin
    Tsvetomir avatar
    196 posts

    Posted 11 Sep 2018 Link to this post

    Hi Samuel,

    If you modify a default functionality, the control might misbehave, in our case - visually. If you would like to stick to implementing custom logic, you can create your own custom buttons with custom CommandName property - "MyInsertCommand" for example. Those buttons should not init the built-in commands at all. After executing your custom logic you can invoke the default command:
    https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/control-lifecycle/how-to-fire-command-events 

    If you require further clarifications on the topic, feel free to contact us.

    Kind regards,
    Tsvetomir
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top