This is a migrated thread and some comments may be shown as answers.

Window grid editing

2 Answers 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Luca B
Top achievements
Rank 1
Luca B asked on 24 Jun 2013, 11:10 AM
Hi there,
I created a control that inherits from RadGrid to include a RadWindow editing feature, similar to the sample here http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=grid
The main difference is that I do not want to use an external page, as in the sample above, but I want to use a template to be dynamically loaded in the RadWindow. Also, I'd like to handle all load & save events using the RadGrid ItemCommand.
So I created an ITemplate EditWindowTemplate property in my control and I instantiate it in the RadWindow contentcontainer when needed.
This is the code I use to extend the RadGrid js client 
Telerik.Web.UI.RadGrid.prototype.showEditItemForm = function (itemIndex) {
    this.gridItemIndex = itemIndex;
    $find(this.windowId).show();
    __doPostBack(this.panelId, itemIndex);
    return false;
}
Telerik.Web.UI.RadGrid.prototype.saveChanges = function () {
    if (this.gridItemIndex > -1)
        this.get_masterTableView().fireCommand('Update', '');
    else
        this.get_masterTableView().fireCommand('PerformInsert', '');
}
So, when the user click the "Add new" link or an Edit link, I start a partial postback that loads the RadWindow contents, using an UpdatePanel.
This is the UpdatePanel PreRender method I use to display the UI and pass the edit item index to the server
void pnlWnd_PreRender(object sender, EventArgs e)
        {
            //Handle updatepanel postback, show edit window
            string eventTarget = HttpContext.Current.Request.Params["__EVENTTARGET"] as string;
            int eventArg = -1;
            if (!string.IsNullOrEmpty(eventTarget) && eventTarget == pnlWnd.ClientID && int.TryParse(HttpContext.Current.Request.Params["__EVENTARGUMENT"], out eventArg))
            {
                //CreateEditWindow();
                editWindowContainer.Visible = true;
                if (eventArg > -1)
                {
                    GridCommandEventArgs args = new GridCommandEventArgs(this.Items[eventArg], this, new CommandEventArgs(RadGrid.EditCommandName, null));
                    OnItemCommand(args);
                }
                else
                {
                    MasterTableView.IsItemInserted = true;
                    GridCommandEventArgs args = new GridCommandEventArgs(MasterTableView.GetItems(GridItemType.CommandItem)[0], this, new CommandEventArgs(InitInsertCommandName, -1));
                    OnItemCommand(args);
                }
            }
        }
If the user clicks on the Add link, I fire the InitInsert event, if he clicks an Edit link I fire the Edit event.
Last, I handle the ItemCommand event in a page to respond to each event: Edit (load an item and show the edit form), InitInsert (show empty edit form), Update (the user saved a change) and PerformInsert (the user saved a new item).
When I create a new item everything works, but when I try to save a change to an existing item I get

Specified argument was out of the range of valid values.
Parameter name: ItemHierarchicalIndex

What am I doing wrong?
Thanks!

2 Answers, 1 is accepted

Sort by
0
Luca B
Top achievements
Rank 1
answered on 25 Jun 2013, 10:20 AM
In my search for a solution to this issue I stumbled upon this KB link but it is broken!
Looking at the title alone it seems it could use the approach I am trying to implement.
Any chance you Telerik guys can recover the article?
Thanks!
0
Luca B
Top achievements
Rank 1
answered on 25 Jun 2013, 10:26 AM
In my search for a solution to this issue I stumbled upon this KB link but it is broken!
Looking at the title alone it seems it could use the approach I am trying to implement.
Any chance you Telerik guys can recover the article?
Thanks!
Tags
Grid
Asked by
Luca B
Top achievements
Rank 1
Answers by
Luca B
Top achievements
Rank 1
Share this question
or