or
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);
}
}
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);
}
}
}