Hi,
Currently I have a RadGrid that allows me to user a usercontrol to add and edit. My only issue now is that I need the usercontrol to return an object to the page holding the RadGrid. To do this I have created a custom event handler in the usercontrol. At time of edit or insert I assign a local method to the event:
This only good to get the event attached but since the content is dynamic I have to re-attach the method to the ItemInserted event. I can successfully re-attach the method to the event when in insert mode at page_load but I cannot achieve this in edit mode. See code (comments inside to explain the point of failure)
Currently I have a RadGrid that allows me to user a usercontrol to add and edit. My only issue now is that I need the usercontrol to return an object to the page holding the RadGrid. To do this I have created a custom event handler in the usercontrol. At time of edit or insert I assign a local method to the event:
if (e.Item.IsInEditMode){ GridEditFormItem editItem = e.Item as GridEditFormItem; object EditControl = e.Item.FindControl(GridEditFormInsertItem.EditFormUserControlID); if (EditControl is ValanceProfileCoilLength) { ValanceProfileCoilLength CL = (ValanceProfileCoilLength)EditControl; CL.ItemInserted += new ValanceProfileCoilLength.ItemInsertedEventHandler(CL_ItemInserted); REC_ValanceProfileCoilLength ACL; if (e.Item.ItemIndex >= 0) ACL = this.VP.ActiveCoilLengths[e.Item.ItemIndex]; else ACL = new REC_ValanceProfileCoilLength(null, this.ConnString); CL.Show(ACL); }}This only good to get the event attached but since the content is dynamic I have to re-attach the method to the ItemInserted event. I can successfully re-attach the method to the event when in insert mode at page_load but I cannot achieve this in edit mode. See code (comments inside to explain the point of failure)
protected void Page_Load(object sender, EventArgs e){ // Re-attach method to events in EditForm UserControls // Insert EditForm if (this.grdCoilLengths.MasterTableView.IsItemInserted) { object EditForm = this.grdCoilLengths.MasterTableView.GetInsertItem().FindControl("EditFormControl"); ValanceProfileCoilLength CL = (ValanceProfileCoilLength)EditForm; CL.ItemInserted += new ValanceProfileCoilLength.ItemInsertedEventHandler(CL_ItemInserted); // <-- This works when in insert mode } // Edit EditForm (Only one edit form allowed at once) if (this.grdCoilLengths.EditItems.Count > 0) { object EditControl = this.grdCoilLengths.EditItems[0].FindControl(GridEditFormInsertItem.EditFormUserControlID); // <-- This returns null when in edit mode if (EditControl is ValanceProfileCoilLength) { ValanceProfileCoilLength CL = (ValanceProfileCoilLength)EditControl; CL.ItemInserted += new ValanceProfileCoilLength.ItemInsertedEventHandler(CL_ItemInserted); } }}