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
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
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.
What am I doing wrong?
Thanks!
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', '');}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); } } }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!